PipeWire 1.2.5
Loading...
Searching...
No Matches
ratelimit.h
1/* Ratelimit */
2/* SPDX-FileCopyrightText: Copyright © 2023 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef SPA_RATELIMIT_H
6#define SPA_RATELIMIT_H
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12#include <inttypes.h>
13#include <stddef.h>
14
15struct spa_ratelimit {
16 uint64_t interval;
17 uint64_t begin;
18 unsigned burst;
19 unsigned n_printed;
20 unsigned n_suppressed;
21};
23static inline int spa_ratelimit_test(struct spa_ratelimit *r, uint64_t now)
25 unsigned suppressed = 0;
26 if (r->begin + r->interval < now) {
27 suppressed = r->n_suppressed;
28 r->begin = now;
29 r->n_printed = 0;
30 r->n_suppressed = 0;
31 } else if (r->n_printed >= r->burst) {
32 r->n_suppressed++;
33 return -1;
34 }
35 r->n_printed++;
36 return suppressed;
37}
38
39#ifdef __cplusplus
40} /* extern "C" */
41#endif
42
43#endif /* SPA_RATELIMIT_H */
Definition ratelimit.h:19
unsigned n_suppressed
Definition ratelimit.h:24
uint64_t interval
Definition ratelimit.h:20
uint64_t begin
Definition ratelimit.h:21
unsigned burst
Definition ratelimit.h:22
unsigned n_printed
Definition ratelimit.h:23