]>
| Commit | Line | Data |
|---|---|---|
| db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| c2f1db8f | 2 | #pragma once |
| 1e2e8133 | 3 | |
| f102bc3e | 4 | #include "basic-forward.h" |
| 1e2e8133 LP |
5 | |
| 6 | typedef struct RateLimit { | |
| 8c227e7f ZJS |
7 | usec_t interval; /* Keep those two fields first so they can be initialized easily: */ |
| 8 | unsigned burst; /* RateLimit rl = { INTERVAL, BURST }; */ | |
| 4ce9faa9 | 9 | unsigned num; |
| 8c227e7f | 10 | usec_t begin; |
| 1e2e8133 LP |
11 | } RateLimit; |
| 12 | ||
| fed25720 ZJS |
13 | #define RATELIMIT_OFF (const RateLimit) { .interval = USEC_INFINITY, .burst = UINT_MAX } |
| 14 | ||
| 8c227e7f ZJS |
15 | static inline void ratelimit_reset(RateLimit *rl) { |
| 16 | rl->num = rl->begin = 0; | |
| 17 | } | |
| 451b34cc | 18 | |
| 2031fe74 | 19 | static inline bool ratelimit_configured(const RateLimit *rl) { |
| 2a155c53 LP |
20 | return rl->interval > 0 && rl->burst > 0; |
| 21 | } | |
| 22 | ||
| 2031fe74 | 23 | bool ratelimit_below(RateLimit *rl); |
| 34683dbd | 24 | |
| 2031fe74 | 25 | unsigned ratelimit_num_dropped(const RateLimit *rl); |
| 7223d500 LB |
26 | |
| 27 | usec_t ratelimit_end(const RateLimit *rl); | |
| 53d6987f | 28 | usec_t ratelimit_left(const RateLimit *rl); |