pub struct Condition { /* private fields */ }Implementations§
Source§impl Condition
impl Condition
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Const-init an empty condition variable (Zig: .{}). Required for
static items — this is the parking_lot::Condvar::new() parity that
std::sync::Condvar lacks.
Sourcepub fn wait(&self, mutex: &Mutex)
pub fn wait(&self, mutex: &Mutex)
Atomically releases the Mutex, blocks the caller thread, then re-acquires the Mutex on return. “Atomically” here refers to accesses done on the Condition after acquiring the Mutex.
The Mutex must be locked by the caller’s thread when this function is called. A Mutex can have multiple Conditions waiting with it concurrently, but not the opposite. It is undefined behavior for multiple threads to wait ith different mutexes using the same Condition concurrently. Once threads have finished waiting with one Mutex, the Condition can be used to wait with another Mutex.
A blocking call to wait() is unblocked from one of the following conditions:
- a spurious (“at random”) wake up occurs
- a future call to
signal()orbroadcast()which has acquired the Mutex and is sequenced after thiswait().
Given wait() can be interrupted spuriously, the blocking condition should be checked continuously
irrespective of any notifications from signal() or broadcast().
Sourcepub fn timed_wait(
&self,
mutex: &Mutex,
timeout_ns: u64,
) -> Result<(), TimeoutError>
pub fn timed_wait( &self, mutex: &Mutex, timeout_ns: u64, ) -> Result<(), TimeoutError>
Atomically releases the Mutex, blocks the caller thread, then re-acquires the Mutex on return. “Atomically” here refers to accesses done on the Condition after acquiring the Mutex.
The Mutex must be locked by the caller’s thread when this function is called. A Mutex can have multiple Conditions waiting with it concurrently, but not the opposite. It is undefined behavior for multiple threads to wait ith different mutexes using the same Condition concurrently. Once threads have finished waiting with one Mutex, the Condition can be used to wait with another Mutex.
A blocking call to timed_wait() is unblocked from one of the following conditions:
- a spurious (“at random”) wake occurs
- the caller was blocked for around
timeout_nsnanoseconds, in whichTimeoutError::Timeoutis returned. - a future call to
signal()orbroadcast()which has acquired the Mutex and is sequenced after thistimed_wait().
Given timed_wait() can be interrupted spuriously, the blocking condition should be checked continuously
irrespective of any notifications from signal() or broadcast().
Sourcepub fn signal(&self)
pub fn signal(&self)
Unblocks at least one thread blocked in a call to wait() or timed_wait() with a given Mutex.
The blocked thread must be sequenced before this call with respect to acquiring the same Mutex in order to be observable for unblocking.
signal() can be called with or without the relevant Mutex being acquired and have no “effect” if there’s no observable blocked threads.
Sourcepub fn broadcast(&self)
pub fn broadcast(&self)
Unblocks all threads currently blocked in a call to wait() or timed_wait() with a given Mutex.
The blocked threads must be sequenced before this call with respect to acquiring the same Mutex in order to be observable for unblocking.
broadcast() can be called with or without the relevant Mutex being acquired and have no “effect” if there’s no observable blocked threads.
Sourcepub fn wait_guarded<T>(&self, guard: &mut GuardedLock<'_, T, Mutex>)
pub fn wait_guarded<T>(&self, guard: &mut GuardedLock<'_, T, Mutex>)
wait for callers holding a GuardedLock.
Sourcepub fn timed_wait_guarded<T>(
&self,
guard: &mut GuardedLock<'_, T, Mutex>,
timeout_ns: u64,
) -> Result<(), TimeoutError>
pub fn timed_wait_guarded<T>( &self, guard: &mut GuardedLock<'_, T, Mutex>, timeout_ns: u64, ) -> Result<(), TimeoutError>
timed_wait for callers holding a GuardedLock.
Sourcepub fn notify_one(&self)
pub fn notify_one(&self)
Alias for signal — parking_lot::Condvar spelling.
Sourcepub fn notify_all(&self)
pub fn notify_all(&self)
Alias for broadcast — parking_lot::Condvar spelling.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Condition
impl RefUnwindSafe for Condition
impl Send for Condition
impl Sync for Condition
impl Unpin for Condition
impl UnsafeUnpin for Condition
impl UnwindSafe for Condition
Blanket Implementations§
Source§impl<T> AsCtxPtr for Twhere
T: ?Sized,
impl<T> AsCtxPtr for Twhere
T: ?Sized,
Source§fn as_ctx_ptr(&self) -> *mut Selfwhere
Self: Sized,
fn as_ctx_ptr(&self) -> *mut Selfwhere
Self: Sized,
self’s address as *mut Self for deferred-task / scopeguard /
RefPtr::init_ref ctx slots. The closures/trampolines deref it as shared
(&*p) — every method they reach is &self post-R-2, so no write
provenance is required; the *mut spelling is purely to match the
existing HasAutoFlush / RefCount ABI.