pub(crate) struct Wheel {
elapsed: u64,
levels: Box<[Level; 6]>,
pending: LinkedList<TimerShared, TimerShared>,
}
Expand description
Timing wheel implementation.
This type provides the hashed timing wheel implementation that backs Timer
and DelayQueue
.
The structure is generic over T: Stack
. This allows handling timeout data
being stored on the heap or in a slab. In order to support the latter case,
the slab must be passed into each function allowing the implementation to
lookup timer entries.
See Timer
documentation for some implementation notes.
Fields§
§elapsed: u64
The number of milliseconds elapsed since the wheel started.
levels: Box<[Level; 6]>
Timer wheel.
Levels:
- 1 ms slots / 64 ms range
- 64 ms slots / ~ 4 sec range
- ~ 4 sec slots / ~ 4 min range
- ~ 4 min slots / ~ 4 hr range
- ~ 4 hr slots / ~ 12 day range
- ~ 12 day slots / ~ 2 yr range
pending: LinkedList<TimerShared, TimerShared>
Entries queued for firing
Implementations§
source§impl Wheel
impl Wheel
sourcepub(crate) fn elapsed(&self) -> u64
pub(crate) fn elapsed(&self) -> u64
Returns the number of milliseconds that have elapsed since the timing wheel’s creation.
sourcepub(crate) unsafe fn insert(
&mut self,
item: TimerHandle,
) -> Result<u64, (TimerHandle, InsertError)>
pub(crate) unsafe fn insert( &mut self, item: TimerHandle, ) -> Result<u64, (TimerHandle, InsertError)>
Inserts an entry into the timing wheel.
§Arguments
item
: The item to insert into the wheel.
§Return
Returns Ok
when the item is successfully inserted, Err
otherwise.
Err(Elapsed)
indicates that when
represents an instant that has
already passed. In this case, the caller should fire the timeout
immediately.
Err(Invalid)
indicates an invalid when
argument as been supplied.
§Safety
This function registers item into an intrusive linked list. The caller
must ensure that item
is pinned and will not be dropped without first
being deregistered.
sourcepub(crate) unsafe fn remove(&mut self, item: NonNull<TimerShared>)
pub(crate) unsafe fn remove(&mut self, item: NonNull<TimerShared>)
Removes item
from the timing wheel.
sourcepub(crate) fn poll(&mut self, now: u64) -> Option<TimerHandle>
pub(crate) fn poll(&mut self, now: u64) -> Option<TimerHandle>
Advances the timer up to the instant represented by now
.
sourcefn next_expiration(&self) -> Option<Expiration>
fn next_expiration(&self) -> Option<Expiration>
Returns the instant at which the next timeout expires.
sourcepub(super) fn next_expiration_time(&self) -> Option<u64>
pub(super) fn next_expiration_time(&self) -> Option<u64>
Returns the tick at which this timer wheel next needs to perform some processing, or None if there are no timers registered.
sourcefn no_expirations_before(&self, start_level: usize, before: u64) -> bool
fn no_expirations_before(&self, start_level: usize, before: u64) -> bool
Used for debug assertions
sourcepub(crate) fn process_expiration(&mut self, expiration: &Expiration)
pub(crate) fn process_expiration(&mut self, expiration: &Expiration)
iteratively find entries that are between the wheel’s current time and the expiration time. for each in that population either queue it for notification (in the case of the last level) or tier it down to the next level (in all other cases).
fn set_elapsed(&mut self, when: u64)
sourcefn take_entries(
&mut self,
expiration: &Expiration,
) -> LinkedList<TimerShared, TimerShared>
fn take_entries( &mut self, expiration: &Expiration, ) -> LinkedList<TimerShared, TimerShared>
Obtains the list of entries that need processing for the given expiration.