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
1 TICK_MSInitial tick duration (base granularity).
8 LEVEL0_BITSLevel 0 configuration (256 slots).
1 << LEVEL0_BITS LEVEL0_SIZE
LEVEL0_SIZE - 1 LEVEL0_MASK
6 LEVELN_BITSHigher levels configuration (64 slots each).
1 << LEVELN_BITS LEVELN_SIZE
LEVELN_SIZE - 1 LEVELN_MASK
4 NUM_LEVELSTotal number of levels.
LEVEL0_SIZE + (NUM_LEVELS - 1) * LEVELN_SIZE TOTAL_SLOTSTotal number of slots across all levels.
Slot[TOTAL_SLOTS] _allSlotsFixed-size array of slots for all levels.
uint[NUM_LEVELS] _offsetsOffsets into `allSlots` for each level.
long _currentTickMonotonic tick counter advancing 1ms at a time.
size_t _activeCountTotal number of active timers in the wheel.
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.
SlotInfo computeSlot(long deadline) const pure @safe nothrow @nogc
void link(uint level, uint index, Entry * entry) @safe nothrow @nogc
void unlink(uint level, uint index, Entry * entry) @safe nothrow @nogc
Entry * collect(uint level, uint index) @safe nothrow @nogc
void cascade(uint level, Entry * * expiredHead) @trusted nothrow @nogc
Nested Templates
EntryIntrusive node for the timing wheel's linked lists.
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.