Struct std::TimerWheel
struct TimerWheel {
struct WheelTimer timers[WHEEL_TIMERS];
unsigned long current_tick;
}Fields
slots[s] stores timer index+1 for the head of the list in bucket s, 0 means the bucket is empty. Chaining uses timers[id].ctx as next pointer only conceptually; this implementation uses a flat scan for simplicity and correctness within the WHEEL_TIMERS limit.
Methods
Initialise the wheel in place to a clean state (all slots free, tick = 0). Must be called before any other operation.
One-shot timer calling cb(ctx) at absolute tick tick.
Returns the timer ID (1-based) or 0 if the wheel is full.
Periodic timer calling cb(ctx) every period ticks, first at
current_tick + period. Returns the timer ID (1-based) or 0 if full.
Cancel a timer by its ID. Silently ignores invalid IDs.
Advance the wheel by one tick; fires all timers expiring at the new tick. Periodic timers are automatically rescheduled. Returns the number of timers fired.
Return the current tick counter.