Struct tm_wheel::TimerDriverBase
source · pub struct TimerDriverBase<T, A: SlabAllocator<TimerNode<T>>, const LEVELS: usize, const WHEEL_SIZE: usize> { /* private fields */ }
Expand description
Basic timer driver with manually configurable page size / slab allocator.
WHEELS
: Number of timing wheel hierarchy.WHEEL_LENGTH
: Number of slots in each page. This MUST be power of 2.
Implementations§
source§impl<T, A: SlabAllocator<TimerNode<T>>, const LEVELS: usize, const WHEEL_SIZE: usize> TimerDriverBase<T, A, LEVELS, WHEEL_SIZE>
impl<T, A: SlabAllocator<TimerNode<T>>, const LEVELS: usize, const WHEEL_SIZE: usize> TimerDriverBase<T, A, LEVELS, WHEEL_SIZE>
pub const LEVELS: usize = LEVELS
pub fn new(slab: A) -> Self
sourcepub fn insert(&mut self, value: T, expires_at: TimePoint) -> TimerHandle
pub fn insert(&mut self, value: T, expires_at: TimePoint) -> TimerHandle
Insert new timer with expiration time point.
§Panics
- Specified timer expiration is out of range.
- Active timer instance is larger than 2^32-1
sourcepub fn expiration_limit(&self) -> TimeOffset
pub fn expiration_limit(&self) -> TimeOffset
Get the maximum amount of time that can be set for a timer. Returned value is offset time from the current time point.
sourcepub fn remove(&mut self, handle: TimerHandle) -> Option<T>
pub fn remove(&mut self, handle: TimerHandle) -> Option<T>
Remove given timer handle from the driver.
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserve the space for additional timers. If underlying SlabAllocator
doesn’t
support it, this method does nothing.
sourcepub fn reset(&mut self, now: TimePoint)
pub fn reset(&mut self, now: TimePoint)
Remove all timers. Time point regression is only allowed if the driver is empty.
sourcepub fn nearest_wakeup(&mut self) -> Option<NonZeroU64>
pub fn nearest_wakeup(&mut self) -> Option<NonZeroU64>
Suggested timing for next wakeup. It is guaranteed that none of the timers will be overslept until returned time point.
If there’s no nearest timer in lowest level page, it’ll return the nearest rehash timing which will drag down the timers from higher pages, resulting no actual timer expiration output.
sourcepub fn advance_to(
&mut self,
time_point: TimePoint
) -> TimerDriverDrainIter<'_, T, A, LEVELS, WHEEL_SIZE> ⓘ
pub fn advance_to( &mut self, time_point: TimePoint ) -> TimerDriverDrainIter<'_, T, A, LEVELS, WHEEL_SIZE> ⓘ
Advance timer driver to the given time point.
§Warning
Expiration order is not guaranteed. It’s caller’s responsibility to handle correct expiration order.
§Panics
Panics if the given time point is less than the current time point. Same time point doesn’t cause panic, as it’s meaningful for timer insertions that are already expired.
sourcepub fn advance(
&mut self,
advance: TimeOffset
) -> TimerDriverDrainIter<'_, T, A, LEVELS, WHEEL_SIZE> ⓘ
pub fn advance( &mut self, advance: TimeOffset ) -> TimerDriverDrainIter<'_, T, A, LEVELS, WHEEL_SIZE> ⓘ
Advance timer by timer amount.
Trait Implementations§
source§impl<T: Clone, A: Clone + SlabAllocator<TimerNode<T>>, const LEVELS: usize, const WHEEL_SIZE: usize> Clone for TimerDriverBase<T, A, LEVELS, WHEEL_SIZE>
impl<T: Clone, A: Clone + SlabAllocator<TimerNode<T>>, const LEVELS: usize, const WHEEL_SIZE: usize> Clone for TimerDriverBase<T, A, LEVELS, WHEEL_SIZE>
source§fn clone(&self) -> TimerDriverBase<T, A, LEVELS, WHEEL_SIZE>
fn clone(&self) -> TimerDriverBase<T, A, LEVELS, WHEEL_SIZE>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more