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