Skip to main content

RawCondvar

Trait RawCondvar 

Source
pub unsafe trait RawCondvar {
    type RawMutex: RawMutex;

    const INIT: Self;

    // Required methods
    unsafe fn wait(
        &self,
        mutex: &Self::RawMutex,
        guard: &mut <Self::RawMutex as RawMutex>::Guard,
    );
    fn notify_one(&self) -> bool;
    fn notify_all(&self) -> usize;
}
Expand description

Basic operations for a condition variable associated with a particular RawMutex implementation.

Types implementing this trait can be used by Condvar to form a safe condition variable type.

Implementations must document whether they guarantee no spurious wakeups. If they do, notification methods report exactly how many threads were notified. Otherwise, notification methods must return false or 0, and all non-timeout wakeups are treated as potentially spurious. In either case, notification methods must still wake waiting threads as specified.

§Safety

wait must atomically unlock the mutex and begin waiting with respect to calls to notify_one and notify_all, then re-lock the mutex before it returns.

If a wait panics after unlocking the mutex, it must re-lock the mutex before unwinding, and replace guard with the state of the new acquisition. guard must remain valid on both normal return and unwind. If restoring ownership or valid guard state fails, the implementation must abort. Implementations which cannot wait on distinct mutexes simultaneously may panic when asked to do so, but must not cause undefined behavior.

Required Associated Constants§

Source

const INIT: Self

Initial value for a new condvar.

Required Associated Types§

Source

type RawMutex: RawMutex

The type of RawMutex this condvar can work with.

Required Methods§

Source

unsafe fn wait( &self, mutex: &Self::RawMutex, guard: &mut <Self::RawMutex as RawMutex>::Guard, )

Atomically unlocks the mutex and waits, then re-locks the mutex before returning.

This method may return spuriously. See the implementation’s documentation for any stronger guarantees.

§Safety

The caller must logically hold mutex, with guard containing the state of that acquisition. The protected data must not be accessed from the time this method unlocks the mutex until it re-locks it.

Source

fn notify_one(&self) -> bool

Notifies one waiting thread.

If the implementation guarantees no spurious wakeups, returns whether this call notified a waiting thread. Otherwise, must return false. Threads whose waits end because of a timeout are not counted.

Source

fn notify_all(&self) -> usize

Notifies all waiting threads.

If the implementation guarantees no spurious wakeups, returns the exact number of waiting threads this call notified. Otherwise, must return 0. Threads whose waits end because of a timeout are not counted.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§