std1.0.0-beta-7 SafeC docs

std :: dsp::timer_wheel

Struct std::TimerWheel

#include <std/dsp/timer_wheel.h> source

struct TimerWheel {
    struct WheelTimer timers[WHEEL_TIMERS];
    unsigned long current_tick;
}

Fields

§unsigned long current_ticksource

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

§void init()source · definition

Initialise the wheel in place to a clean state (all slots free, tick = 0). Must be called before any other operation.

§generic<T> int add(unsigned long tick, fn void(?&T) cb, ?&T ctx)source · definition

One-shot timer calling cb(ctx) at absolute tick tick. Returns the timer ID (1-based) or 0 if the wheel is full.

§generic<T> int add_periodic(unsigned long period, fn void(?&T) cb, ?&T ctx)source · definition

Periodic timer calling cb(ctx) every period ticks, first at current_tick + period. Returns the timer ID (1-based) or 0 if full.

§void cancel(int id)source · definition

Cancel a timer by its ID. Silently ignores invalid IDs.

§int tick()source · definition

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.

§unsigned long now() constsource · definition

Return the current tick counter.