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