Skip to main content

Condition

Struct Condition 

Source
pub struct Condition { /* private fields */ }

Implementations§

Source§

impl Condition

Source

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.

Source

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() or broadcast() which has acquired the Mutex and is sequenced after this wait().

Given wait() can be interrupted spuriously, the blocking condition should be checked continuously irrespective of any notifications from signal() or broadcast().

Source

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_ns nanoseconds, in which TimeoutError::Timeout is returned.
  • a future call to signal() or broadcast() which has acquired the Mutex and is sequenced after this timed_wait().

Given timed_wait() can be interrupted spuriously, the blocking condition should be checked continuously irrespective of any notifications from signal() or broadcast().

Source

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.

Source

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.

Source

pub fn wait_guarded<T>(&self, guard: &mut GuardedLock<'_, T, Mutex>)

wait for callers holding a GuardedLock.

Source

pub fn timed_wait_guarded<T>( &self, guard: &mut GuardedLock<'_, T, Mutex>, timeout_ns: u64, ) -> Result<(), TimeoutError>

timed_wait for callers holding a GuardedLock.

Source

pub fn notify_one(&self)

Alias for signal — parking_lot::Condvar spelling.

Source

pub fn notify_all(&self)

Alias for broadcast — parking_lot::Condvar spelling.

Trait Implementations§

Source§

impl Default for Condition

Source§

fn default() -> Condition

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsCtxPtr for T
where T: ?Sized,

Source§

fn as_ctx_ptr(&self) -> *mut Self
where 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.
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V