Struct tokio::runtime::time::entry::TimerHandle

source ·
pub(crate) struct TimerHandle {
    inner: NonNull<TimerShared>,
}
Expand description

An TimerHandle is the (non-enforced) “unique” pointer from the driver to the timer entry. Generally, at most one TimerHandle exists for a timer at a time (enforced by the timer state machine).

SAFETY: An TimerHandle is essentially a raw pointer, and the usual caveats of pointer safety apply. In particular, TimerHandle does not itself enforce that the timer does still exist; however, normally an TimerHandle is created immediately before registering the timer, and is consumed when firing the timer, to help minimize mistakes. Still, because TimerHandle cannot enforce memory safety, all operations are unsafe.

Fields§

§inner: NonNull<TimerShared>

Implementations§

source§

impl TimerHandle

source

pub(super) unsafe fn cached_when(&self) -> u64

source

pub(super) unsafe fn sync_when(&self) -> u64

source

pub(super) unsafe fn is_pending(&self) -> bool

source

pub(super) unsafe fn set_expiration(&self, tick: u64)

Forcibly sets the true and cached expiration times to the given tick.

SAFETY: The caller must ensure that the handle remains valid, the driver lock is held, and that the timer is not in any wheel linked lists.

source

pub(super) unsafe fn mark_pending(&self, not_after: u64) -> Result<(), u64>

Attempts to mark this entry as pending. If the expiration time is after not_after, however, returns an Err with the current expiration time.

If an Err is returned, the cached_when value will be updated to this new expiration time.

SAFETY: The caller must ensure that the handle remains valid, the driver lock is held, and that the timer is not in any wheel linked lists. After returning Ok, the entry must be added to the pending list.

source

pub(super) unsafe fn fire( self, completed_state: Result<(), Error>, ) -> Option<Waker>

Attempts to transition to a terminal state. If the state is already a terminal state, does nothing.

Because the entry might be dropped after the state is moved to a terminal state, this function consumes the handle to ensure we don’t access the entry afterwards.

Returns the last-registered waker, if any.

SAFETY: The driver lock must be held while invoking this function, and the entry must not be in any wheel linked lists.

Trait Implementations§

source§

impl Debug for TimerHandle

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.