36#ifndef _UTILS_LIMITTIMER_HXX_
37#define _UTILS_LIMITTIMER_HXX_
54 std::function<
void()> callback)
55 :
Timer(ex->active_timers())
57 ,
bucket_(std::min(static_cast<uint8_t>(127), max_tokens))
This class implements an execution of tasks pulled off an input queue.
This timer takes care of limiting the number of speed updates we send out in a second.
LimitTimer(ExecutorBase *ex, uint16_t update_delay_msec, uint8_t max_tokens, std::function< void()> callback)
Constructor.
uint16_t updateDelayMsec_
cooldown delay in msec
uint8_t bucketMax_
maximum number of tokens in the bucket
void take_no_callback()
Takes one entry from the bucket, and does not give a callback if there is no entry left.
std::function< void()> callback_
callback after cooldown period.
uint8_t needUpdate_
if non-zero, wake up parent when token is available.
long long timeout() override
Callback from the timer infrastructure. Called periodically.
uint8_t bucket_
number of available tokens
bool try_take()
Attempts to take a token out of the bucket.
A timer that can schedule itself to run on an executor at specified times in the future.
void cancel()
Dangerous, do not call.
@ RESTART
Restart the timer with existing period.
@ NONE
Do not restart the timer.
void start(long long period=-1)
Starts a timer.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
#define MSEC_TO_NSEC(_msec)
Convert a millisecond value to a nanosecond value.