Skip to main content

OwnedCondvar

Struct OwnedCondvar 

Source
pub struct OwnedCondvar { /* private fields */ }
Expand description

A condvar that owns its underlying raw condvar, which is destroyed when OwnedCondvar is dropped. If you want to construct a condvar in shared memory for IPC, use a BorrowedCondvar instead.

The methods are safe because the allocation belongs to this object, and because the POSIX invariant that every concurrent waiter passes a guard belonging to the same mutex is checked at runtime rather than left to the caller.

Implementations§

Source§

impl OwnedCondvar

Source

pub fn new() -> Self

Creates a condvar with the default attributes. Use CondvarBuilder to set any of the others.

Source

pub fn clock(&self) -> CondvarClock

The clock this condvar resolves the deadlines of its timed waits against.

Source

pub fn notify_one(&self) -> Result<(), CondvarSignalError>

Wakes one thread waiting on this condvar, if there is one. This is pthread_cond_signal.

§Errors

See CondvarSignalError

Source

pub fn notify_all(&self) -> Result<(), CondvarSignalError>

Wakes every thread waiting on this condvar. This is pthread_cond_broadcast.

§Errors

See CondvarSignalError

Source

pub fn wait<G>(&self, guard: &mut G) -> Result<(), CondvarWaitError>
where G: MutexGuard,

Releases the mutex guard belongs to, blocks until this condvar is notified, and takes the mutex again before returning. The guard is still valid afterwards, so the critical section simply proceeds.

Wakeups are permitted to be spurious, so this should be wrapped in a loop that re-checks the predicate:

let mut guard = mtx.lock().unwrap();
while !predicate_holds() {
    cv.wait(&mut guard).unwrap();
}
§Panics

Panics if a previous wait on this condvar used a guard belonging to a different mutex.

§Errors

See CondvarWaitError

Source

pub fn wait_for<G>( &self, guard: &mut G, timeout: Duration, ) -> Result<WaitOutcome, CondvarWaitError>
where G: MutexGuard,

Like wait, but gives up once timeout has elapsed on self.clock(). The mutex is held again on return either way.

§Panics

Panics if a previous wait on this condvar used a guard belonging to a different mutex.

§Errors

See CondvarWaitError

Source

pub fn as_raw_condvar(&self) -> *mut pthread_cond_t

Returns a pointer to the underlying pthread_cond_t.

The pointer stays valid until this OwnedCondvar is dropped.

Trait Implementations§

Source§

impl Debug for OwnedCondvar

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for OwnedCondvar

Source§

fn default() -> Self

Equivalent to CondvarBuilder::new().build_owned().

Source§

impl Drop for OwnedCondvar

Source§

fn drop(&mut self)

Calls pthread_cond_destroy on the underlying condvar.

Every waiter holds a &self, so by the time this runs there cannot be one left.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for OwnedCondvar

Source§

impl Sync for OwnedCondvar

Source§

impl Unpin for OwnedCondvar

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

Source§

type Error = Infallible

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.