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
impl OwnedCondvar
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a condvar with the default attributes. Use CondvarBuilder to set any of the
others.
Sourcepub fn clock(&self) -> CondvarClock
pub fn clock(&self) -> CondvarClock
The clock this condvar resolves the deadlines of its timed waits against.
Sourcepub fn notify_one(&self) -> Result<(), CondvarSignalError>
pub fn notify_one(&self) -> Result<(), CondvarSignalError>
Wakes one thread waiting on this condvar, if there is one. This is
pthread_cond_signal.
§Errors
Sourcepub fn notify_all(&self) -> Result<(), CondvarSignalError>
pub fn notify_all(&self) -> Result<(), CondvarSignalError>
Wakes every thread waiting on this condvar. This is
pthread_cond_broadcast.
§Errors
Sourcepub fn wait<G>(&self, guard: &mut G) -> Result<(), CondvarWaitError>where
G: MutexGuard,
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
Sourcepub fn wait_for<G>(
&self,
guard: &mut G,
timeout: Duration,
) -> Result<WaitOutcome, CondvarWaitError>where
G: MutexGuard,
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
Sourcepub fn as_raw_condvar(&self) -> *mut pthread_cond_t
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
impl Debug for OwnedCondvar
Source§impl Default for OwnedCondvar
impl Default for OwnedCondvar
Source§impl Drop for OwnedCondvar
impl Drop for OwnedCondvar
Source§fn drop(&mut self)
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.