pub struct CondVar { /* private fields */ }
Expand description
Exposes the kernel’s struct wait_queue_head
as a condition variable. It allows the caller to
atomically release the given lock and go to sleep. It reacquires the lock when it wakes up. And
it wakes up when notified by another thread (via CondVar::notify_one
or
CondVar::notify_all
) or because the thread received a signal.
Implementations
sourceimpl CondVar
impl CondVar
sourcepub const unsafe fn new() -> Self
pub const unsafe fn new() -> Self
Constructs a new conditional variable.
Safety
The caller must call CondVar::init
before using the conditional variable.
sourcepub fn wait<L: Lock<I>, I: LockInfo>(&self, guard: &mut Guard<'_, L, I>) -> bool
pub fn wait<L: Lock<I>, I: LockInfo>(&self, guard: &mut Guard<'_, L, I>) -> bool
Atomically releases the given lock (whose ownership is proven by the guard) and puts the
thread to sleep. It wakes up when notified by CondVar::notify_one
or
CondVar::notify_all
, or when the thread receives a signal.
Returns whether there is a signal pending.
sourcepub fn notify_one(&self)
pub fn notify_one(&self)
Wakes a single waiter up, if any. This is not ‘sticky’ in the sense that if no thread is waiting, the notification is lost completely (as opposed to automatically waking up the next waiter).
sourcepub fn notify_all(&self)
pub fn notify_all(&self)
Wakes all waiters up, if any. This is not ‘sticky’ in the sense that if no thread is waiting, the notification is lost completely (as opposed to automatically waking up the next waiter).
sourcepub fn free_waiters(&self)
pub fn free_waiters(&self)
Wakes all waiters up. If they were added by epoll
, they are also removed from the list of
waiters. This is useful when cleaning up a condition variable that may be waited on by
threads that use epoll
.