12#ifndef ROC_CORE_RATE_LIMITER_H_
13#define ROC_CORE_RATE_LIMITER_H_
28 : period_(
Ticker::ticks_t(period))
32 roc_panic(
"rate limiter: expected positive period, got %ld", (
long)period);
38 return ticker_.
elapsed() >= pos_;
44 if (elapsed >= pos_) {
45 pos_ = (elapsed / period_ + 1) * period_;
Base class for non-copyable objects.
RateLimiter(nanoseconds_t period)
Initialize rate limiter.
bool allow()
Check whether an event is allowed to occur now, and if yes, mark it as occurred.
bool would_allow()
Check whether allow() would succeed.
ticks_t elapsed()
Returns number of ticks elapsed since start. If ticker is not started yet, it is started automaticall...
uint64_t ticks_t
Number of ticks.
const nanoseconds_t Nanosecond
One nanosecond represented in nanoseconds.
const nanoseconds_t Second
One second represented in nanoseconds.
int64_t nanoseconds_t
Nanoseconds.
#define roc_panic(...)
Print error message and terminate program gracefully.