eve.core.timer

Types 2

Hierarchical timing wheel for efficient timer management.

  • O(1) insert, O(1) cancel, O(1) amortized expiration check.
  • Granularity: 1ms (tick).
  • Range: ~18 hours (4 levels).
  • No dynamic allocations (uses pre-allocated entries from watcher slots).
Fields
TICK_MSInitial tick duration (base granularity).
LEVEL0_BITSLevel 0 configuration (256 slots).
LEVEL0_SIZE
LEVEL0_MASK
LEVELN_BITSHigher levels configuration (64 slots each).
LEVELN_SIZE
LEVELN_MASK
NUM_LEVELSTotal number of levels.
TOTAL_SLOTSTotal number of slots across all levels.
private Slot[TOTAL_SLOTS] _allSlotsFixed-size array of slots for all levels.
private uint[NUM_LEVELS] _offsetsOffsets into `allSlots` for each level.
private long _currentTickMonotonic tick counter advancing 1ms at a time.
private size_t _activeCountTotal number of active timers in the wheel.
private ulong[4] _level0BitsBitmap of non-empty level-0 slots (256 bits = 4 × ulong).
Methods
size_t count() @property const pure @safe nothrow @nogcReturn the total number of active timers in the wheel.
void reset(long initialTick = 0) @safe nothrow @nogcReset the wheel to its initial state.
void schedule(long delayMs, Entry * entry) @safe nothrow @nogcSchedule a timer entry in the appropriate level and slot.
void cancel(Entry * entry) @safe nothrow @nogcRemove a timer entry from its current slot.
Entry * tick() @trusted nothrow @nogcAdvance the wheel and collect all expired entries.
int nextDeadlineMs() const pure @safe nothrow @nogcReturn the number of milliseconds until the next timer is scheduled to fire.
long currentTick() @property const pure @safe nothrow @nogcReport the current monotonic tick counter.
private SlotInfo computeSlot(long deadline) const pure @safe nothrow @nogc
private void link(uint level, uint index, Entry * entry) @safe nothrow @nogc
private void unlink(uint level, uint index, Entry * entry) @safe nothrow @nogc
private void setLevel0Bit(uint index) @safe nothrow @nogc
private void clearLevel0Bit(uint index) @safe nothrow @nogc
private uint bsf(ulong v) static @safe pure nothrow @nogc
private Entry * collect(uint level, uint index) @safe nothrow @nogc
private void cascade(uint level, Entry * * expiredHead) @trusted nothrow @nogc
Nested Templates
EntryIntrusive node for the timing wheel's linked lists.
SlotA slot in the wheel — head and tail of a doubly-linked list of entries.
SlotInfo
structTimerSpec

Declarative timer configuration stored by the loop.

Fields
long delayMsInitial delay before the first firing, in milliseconds.
long intervalMsRepeating interval in milliseconds. `0` means one-shot.
Methods
bool repeating() @property const pure @safe nothrow @nogcReport whether the timer repeats after the first firing.

Functions 2

fnlong normalizedDelay(long value) pure @safe nothrow @nogcClamp a requested timer delay to the non-negative range accepted by the loop.
fnlong normalizedInterval(long value) pure @safe nothrow @nogcClamp a requested timer interval to the non-negative range accepted by the loop.