| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "basic-forward.h" |
| 5 |
|
| 6 |
typedef struct RateLimit { |
| 7 |
usec_t interval; /* Keep those two fields first so they can be initialized easily: */ |
| 8 |
unsigned burst; /* RateLimit rl = { INTERVAL, BURST }; */ |
| 9 |
unsigned num; |
| 10 |
usec_t begin; |
| 11 |
} RateLimit; |
| 12 |
|
| 13 |
#define RATELIMIT_OFF (const RateLimit) { .interval = USEC_INFINITY, .burst = UINT_MAX } |
| 14 |
|
| 15 |
static inline void ratelimit_reset(RateLimit *rl) { |
| 16 |
rl->num = rl->begin = 0; |
| 17 |
} |
| 18 |
|
| 19 |
static inline bool ratelimit_configured(const RateLimit *rl) { |
| 20 |
return rl->interval > 0 && rl->burst > 0; |
| 21 |
} |
| 22 |
|
| 23 |
bool ratelimit_below(RateLimit *rl); |
| 24 |
|
| 25 |
unsigned ratelimit_num_dropped(const RateLimit *rl); |
| 26 |
|
| 27 |
usec_t ratelimit_end(const RateLimit *rl); |
| 28 |
usec_t ratelimit_left(const RateLimit *rl); |