]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/ratelimit.h
logind: Don't match non-leader processes for utmp TTY determination (#38027)
[thirdparty/systemd.git] / src / basic / ratelimit.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
c2f1db8f 2#pragma once
1e2e8133 3
0c15577a 4#include "forward.h"
1e2e8133
LP
5
6typedef struct RateLimit {
8c227e7f
ZJS
7 usec_t interval; /* Keep those two fields first so they can be initialized easily: */
8 unsigned burst; /* RateLimit rl = { INTERVAL, BURST }; */
4ce9faa9 9 unsigned num;
8c227e7f 10 usec_t begin;
1e2e8133
LP
11} RateLimit;
12
fed25720
ZJS
13#define RATELIMIT_OFF (const RateLimit) { .interval = USEC_INFINITY, .burst = UINT_MAX }
14
8c227e7f
ZJS
15static inline void ratelimit_reset(RateLimit *rl) {
16 rl->num = rl->begin = 0;
17}
451b34cc 18
2031fe74 19static inline bool ratelimit_configured(const RateLimit *rl) {
2a155c53
LP
20 return rl->interval > 0 && rl->burst > 0;
21}
22
2031fe74 23bool ratelimit_below(RateLimit *rl);
34683dbd 24
2031fe74 25unsigned ratelimit_num_dropped(const RateLimit *rl);
7223d500
LB
26
27usec_t ratelimit_end(const RateLimit *rl);
53d6987f 28usec_t ratelimit_left(const RateLimit *rl);