12 #ifndef ROC_CORE_RATE_LIMITER_H_
13 #define ROC_CORE_RATE_LIMITER_H_
28 : period_(
Ticker::Ticks(period))
32 roc_panic(
"rate limiter: expected positive period, got %ld", (
long)period);
39 if (elapsed >= pos_) {
40 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.
Ticks elapsed()
Returns number of ticks elapsed since start. If ticker is not started yet, it is started automaticall...
uint64_t Ticks
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.