Struct wait_queue::WaitQueue

source ·
pub struct WaitQueue<P = Spin>where
    P: DeadlockPrevention,{ /* private fields */ }
Expand description

A queue of tasks waiting for an event to occur.

When tasks are popped off the front of the queue via notify_one() or notify_all(), they are each unblocked.

The wait queue uses a mutex internally and hence exposes a deadlock prevention type parameter P, which is [Spin] by default. This parameter should only be set to another deadlock prevention method if a spin-based mutex could lead to deadlock, e.g., in an interrupt context. You do not need to use the DisablePreemption deadlock prevention method here to avoid scheduler race conditions – that is already accounted for in this wait queue’s implementation, even when using the [Spin] default.

Implementations§

source§

impl<P> WaitQueue<P>where P: DeadlockPrevention,

source

pub const fn new() -> Self

Creates a new empty wait queue.

source

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

Blocks the current task until the given condition succeeds.

source

pub fn notify_one(&self) -> bool

Notifies the first task in the wait queue.

If it fails to unblock the first task, it will continue unblocking subsequent tasks until a task is successfully unblocked.

source

pub fn notify_all(&self)

Notifies all the tasks in the wait queue.

Auto Trait Implementations§

§

impl<P = Spin> !RefUnwindSafe for WaitQueue<P>

§

impl<P> Send for WaitQueue<P>

§

impl<P> Sync for WaitQueue<P>

§

impl<P> Unpin for WaitQueue<P>

§

impl<P = Spin> !UnwindSafe for WaitQueue<P>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.