]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/ratelimit.h
tree-wide: remove Lennart's copyright lines
[thirdparty/systemd.git] / src / basic / ratelimit.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include <stdbool.h>
5
6 #include "time-util.h"
7 #include "util.h"
8
9 typedef struct RateLimit {
10 usec_t interval;
11 usec_t begin;
12 unsigned burst;
13 unsigned num;
14 } RateLimit;
15
16 #define RATELIMIT_DEFINE(_name, _interval, _burst) \
17 RateLimit _name = { \
18 .interval = (_interval), \
19 .burst = (_burst), \
20 .num = 0, \
21 .begin = 0 \
22 }
23
24 #define RATELIMIT_INIT(v, _interval, _burst) \
25 do { \
26 RateLimit *_r = &(v); \
27 _r->interval = (_interval); \
28 _r->burst = (_burst); \
29 _r->num = 0; \
30 _r->begin = 0; \
31 } while (false)
32
33 #define RATELIMIT_RESET(v) \
34 do { \
35 RateLimit *_r = &(v); \
36 _r->num = 0; \
37 _r->begin = 0; \
38 } while (false)
39
40 bool ratelimit_below(RateLimit *r);