Skip to main content

WaitQueue

Struct WaitQueue 

Source
pub struct WaitQueue { /* private fields */ }
Expand description

A FIFO queue of tasks waiting for an event.

See the module documentation for usage notes and the lost-wakeup guarantee.

Implementations§

Source§

impl WaitQueue

Source

pub const fn new() -> Self

Create a new empty wait queue.

Source

pub fn wait(&self)

Block the calling task until explicitly woken.

Prefer wait_until when you have a condition to test, to avoid spurious-wakeup loops and to benefit from the compile-time condition guarantee.

§Panics

Panics if called outside of a task context (no current task).

Source

pub fn wait_until<F, T>(&self, condition: F) -> T
where F: FnMut() -> Option<T>,

Block the calling task until condition() returns Some(T).

The condition is checked under the waiters lock, then the task is inserted into the queue (still under the lock) before blocking. This makes the check-then-block sequence atomic with respect to concurrent wake_one() / wake_all() calls.

The task is re-woken for every notification and re-evaluates the condition; spurious wakeups are impossible because the condition is always re-checked before the next sleep.

§Panics

Panics if called outside of a task context (no current task).

Source

pub fn wake_one(&self) -> bool

Wake the first waiting task (FIFO order).

Returns true if a task was successfully woken, false if the queue was empty.

Source

pub fn wake_all(&self) -> usize

Wake all waiting tasks.

Returns the number of tasks that were woken.

Source

pub fn waiter_count(&self) -> usize

Returns the number of tasks currently registered in this queue.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

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

Source§

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.