Struct tokio::runtime::time::wheel::Wheel

source ·
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

source

pub(crate) fn new() -> Wheel

Creates a new timing wheel.

source

pub(crate) fn elapsed(&self) -> u64

Returns the number of milliseconds that have elapsed since the timing wheel’s creation.

source

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.

source

pub(crate) unsafe fn remove(&mut self, item: NonNull<TimerShared>)

Removes item from the timing wheel.

source

pub(crate) fn poll_at(&self) -> Option<u64>

Instant at which to poll.

source

pub(crate) fn poll(&mut self, now: u64) -> Option<TimerHandle>

Advances the timer up to the instant represented by now.

source

fn next_expiration(&self) -> Option<Expiration>

Returns the instant at which the next timeout expires.

source

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.

source

fn no_expirations_before(&self, start_level: usize, before: u64) -> bool

Used for debug assertions

source

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).

source

fn set_elapsed(&mut self, when: u64)

source

fn take_entries( &mut self, expiration: &Expiration, ) -> LinkedList<TimerShared, TimerShared>

Obtains the list of entries that need processing for the given expiration.

source

fn level_for(&self, when: u64) -> usize

Trait Implementations§

source§

impl Debug for Wheel

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Wheel

§

impl !RefUnwindSafe for Wheel

§

impl Send for Wheel

§

impl Sync for Wheel

§

impl Unpin for Wheel

§

impl !UnwindSafe for Wheel

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, 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.