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,
impl<P> WaitQueue<P>where P: DeadlockPrevention,
sourcepub fn wait_until<F, T>(&self, condition: F) -> Twhere
F: FnMut() -> Option<T>,
pub fn wait_until<F, T>(&self, condition: F) -> Twhere F: FnMut() -> Option<T>,
Blocks the current task until the given condition succeeds.
sourcepub fn notify_one(&self) -> bool
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.
sourcepub fn notify_all(&self)
pub fn notify_all(&self)
Notifies all the tasks in the wait queue.