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>

source

pub const LEVELS: usize = LEVELS

source

pub fn new(slab: A) -> Self

source

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
source

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.

source

pub fn remove(&mut self, handle: TimerHandle) -> Option<T>

Remove given timer handle from the driver.

source

pub fn len(&self) -> usize

Get the number of registered timers.

source

pub fn is_empty(&self) -> bool

Check if the driver is empty.

source

pub fn now(&self) -> TimePoint

Get the current time point.

source

pub fn reserve(&mut self, additional: usize)

Reserve the space for additional timers. If underlying SlabAllocator doesn’t support it, this method does nothing.

source

pub fn reset(&mut self, now: TimePoint)

Remove all timers. Time point regression is only allowed if the driver is empty.

source

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.

source

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.

source

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>

source§

fn clone(&self) -> TimerDriverBase<T, A, LEVELS, WHEEL_SIZE>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug, A: Debug + SlabAllocator<TimerNode<T>>, const LEVELS: usize, const WHEEL_SIZE: usize> Debug for TimerDriverBase<T, A, LEVELS, WHEEL_SIZE>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T, A, const LEVELS: usize, const WHEEL_SIZE: usize> Default for TimerDriverBase<T, A, LEVELS, WHEEL_SIZE>
where A: SlabAllocator<TimerNode<T>> + Default,

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T, A, const LEVELS: usize, const WHEEL_SIZE: usize> Freeze for TimerDriverBase<T, A, LEVELS, WHEEL_SIZE>
where A: Freeze,

§

impl<T, A, const LEVELS: usize, const WHEEL_SIZE: usize> RefUnwindSafe for TimerDriverBase<T, A, LEVELS, WHEEL_SIZE>

§

impl<T, A, const LEVELS: usize, const WHEEL_SIZE: usize> Send for TimerDriverBase<T, A, LEVELS, WHEEL_SIZE>
where A: Send, T: Send,

§

impl<T, A, const LEVELS: usize, const WHEEL_SIZE: usize> Sync for TimerDriverBase<T, A, LEVELS, WHEEL_SIZE>
where A: Sync, T: Sync,

§

impl<T, A, const LEVELS: usize, const WHEEL_SIZE: usize> Unpin for TimerDriverBase<T, A, LEVELS, WHEEL_SIZE>
where A: Unpin, T: Unpin,

§

impl<T, A, const LEVELS: usize, const WHEEL_SIZE: usize> UnwindSafe for TimerDriverBase<T, A, LEVELS, WHEEL_SIZE>
where A: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.