]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/ratelimit.h
Use STRLEN in two places
[thirdparty/systemd.git] / src / basic / ratelimit.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
c2f1db8f 2#pragma once
1e2e8133 3
a7334b09
LP
4/***
5 This file is part of systemd.
6
7 Copyright 2010 Lennart Poettering
a7334b09
LP
8***/
9
11c3a366
TA
10#include <stdbool.h>
11
12#include "time-util.h"
1e2e8133
LP
13#include "util.h"
14
15typedef struct RateLimit {
16 usec_t interval;
9d58f1db 17 usec_t begin;
1e2e8133 18 unsigned burst;
4ce9faa9 19 unsigned num;
1e2e8133
LP
20} RateLimit;
21
47be870b
LP
22#define RATELIMIT_DEFINE(_name, _interval, _burst) \
23 RateLimit _name = { \
24 .interval = (_interval), \
25 .burst = (_burst), \
4ce9faa9 26 .num = 0, \
47be870b 27 .begin = 0 \
1e2e8133
LP
28 }
29
47be870b
LP
30#define RATELIMIT_INIT(v, _interval, _burst) \
31 do { \
32 RateLimit *_r = &(v); \
33 _r->interval = (_interval); \
34 _r->burst = (_burst); \
4ce9faa9 35 _r->num = 0; \
47be870b 36 _r->begin = 0; \
acdfc041 37 } while (false)
1e2e8133 38
451b34cc
LP
39#define RATELIMIT_RESET(v) \
40 do { \
41 RateLimit *_r = &(v); \
42 _r->num = 0; \
43 _r->begin = 0; \
44 } while (false)
45
1e2e8133 46bool ratelimit_test(RateLimit *r);