pub struct WaitQueue { /* private fields */ }Expand description
A wait queue for sleeping until a condition becomes true.
Exposes the kernel’s struct wait_queue_head as a Rust wait queue.
A WaitQueue allows a thread to sleep until a caller-supplied condition becomes true,
re-checking the condition on each wake-up. This matches the C wait_event() family of macros.
For waiting with a lock guard (the condition variable pattern), use CondVar
instead.
Instances of WaitQueue need a lock class and to be pinned. The recommended way to create such
instances is with the pin_init! and new_waitqueue! macros.
§Examples
use kernel::sync::{
atomic::{
Atomic,
Relaxed,
},
new_waitqueue,
WaitQueue,
};
#[pin_data]
pub struct Example {
value: Atomic<i32>,
#[pin]
queue: WaitQueue,
}
fn wait_for_value(e: &Example, v: i32) {
e.queue.wait_event(|| e.value.load(Relaxed) == v);
}
fn set_value(e: &Example, v: i32) {
e.value.store(v, Relaxed);
e.queue.wake_up();
}Implementations§
Source§impl WaitQueue
impl WaitQueue
Sourcepub fn new(
name: &'static CStr,
key: Pin<&'static LockClassKey>,
) -> impl PinInit<Self>
pub fn new( name: &'static CStr, key: Pin<&'static LockClassKey>, ) -> impl PinInit<Self>
Constructs a new wait queue initialiser.
Sourcepub fn as_raw(&self) -> *mut wait_queue_head
pub fn as_raw(&self) -> *mut wait_queue_head
Returns a raw pointer to the underlying wait_queue_head.
Sourcepub fn wait_event<F: FnMut() -> bool>(&self, condition: F)
pub fn wait_event<F: FnMut() -> bool>(&self, condition: F)
Sleeps until the condition returns true.
The condition is checked before each sleep and after each wake-up. The wait is uninterruptible.
Sourcepub fn wait_event_interruptible<F: FnMut() -> bool>(
&self,
condition: F,
) -> Result<(), Interrupted>
pub fn wait_event_interruptible<F: FnMut() -> bool>( &self, condition: F, ) -> Result<(), Interrupted>
Sleeps until the condition returns true or a signal is received.
Returns Ok(()) when the condition is met, or Interrupted if interrupted by a signal.
Sourcepub fn wait_event_timeout<F: FnMut() -> bool>(
&self,
condition: F,
timeout: Delta<Jiffy>,
) -> Result<(), TimedOut>
pub fn wait_event_timeout<F: FnMut() -> bool>( &self, condition: F, timeout: Delta<Jiffy>, ) -> Result<(), TimedOut>
Sleeps until the condition returns true or the timeout expires.
Returns Ok(()) when the condition is met, or TimedOut if the timeout elapsed first.
A negative timeout is treated as zero.
Sourcepub fn wait_event_interruptible_timeout<F: FnMut() -> bool>(
&self,
condition: F,
timeout: Delta<Jiffy>,
) -> Result<(), WaitError>
pub fn wait_event_interruptible_timeout<F: FnMut() -> bool>( &self, condition: F, timeout: Delta<Jiffy>, ) -> Result<(), WaitError>
Sleeps until the condition returns true, a signal is received, or the timeout expires.
Returns Ok(()) when the condition is met, or WaitError on signal or timeout.
A negative timeout is treated as zero.
Sourcepub fn wake_up(&self)
pub fn wake_up(&self)
Wakes up waiters.
Wakes all non-exclusive waiters and one exclusive waiter, if any. Matches C’s wake_up().
Sourcepub fn wake_up_all(&self)
pub fn wake_up_all(&self)
Wakes up all waiters.
Wakes all non-exclusive and all exclusive waiters, if any.
Matches C’s wake_up_all().
Sourcepub fn wake_up_sync(&self)
pub fn wake_up_sync(&self)
Like wake_up(), but hints to the scheduler that the current task
expects to sleep soon. Matches C’s wake_up_sync().
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for WaitQueue
impl !RefUnwindSafe for WaitQueue
impl !UnsafeUnpin for WaitQueue
impl Forget for WaitQueue
impl Move for WaitQueue
impl UnwindSafe for WaitQueue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<S, T> IntoSafeCast<T> for Swhere
T: FromSafeCast<S>,
impl<S, T> IntoSafeCast<T> for Swhere
T: FromSafeCast<S>,
Source§fn into_safe_cast(self) -> T
fn into_safe_cast(self) -> T
self into a T. This operation is guaranteed to be lossless.Source§impl<S, T> IntoSafeCastArch<T> for Swhere
T: FromSafeCastArch<S>,
impl<S, T> IntoSafeCastArch<T> for Swhere
T: FromSafeCastArch<S>,
Source§fn into_safe_cast_arch(self) -> T
fn into_safe_cast_arch(self) -> T
self into a T. This operation is guaranteed to be lossless.