chiark / gitweb /
ratelimit start requests
[elogind.git] / ratelimit.h
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #ifndef fooratelimithfoo
4 #define fooratelimithfoo
5
6 #include "util.h"
7
8 typedef struct RateLimit {
9         usec_t interval;
10         unsigned burst;
11         unsigned n_printed, n_missed;
12         usec_t begin;
13 } RateLimit;
14
15 #define RATELIMIT_DEFINE(_name, _interval, _burst)      \
16         RateLimit _name = {                             \
17                 .interval = (_interval),                \
18                 .burst = (_burst),                      \
19                 .n_printed = 0,                         \
20                 .n_missed = 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->n_printed = 0;                       \
30                 r->n_missed = 0;                        \
31                 r->begin = 0;                           \
32         } while (false);
33
34 bool ratelimit_test(RateLimit *r);
35
36 #endif