1 use crate::sys::locks as imp;
2 use crate::sys_common::mutex::MovableMutex;
3 use crate::time::Duration;
7 type CondvarCheck = <imp::MovableMutex as check::CondvarCheck>::Check;
9 /// An OS-based condition variable.
11 inner: imp::MovableCondvar,
16 /// Creates a new condition variable for use.
17 pub fn new() -> Self {
18 Self { inner: imp::MovableCondvar::new(), check: CondvarCheck::new() }
21 /// Signals one waiter on this condition variable to wake up.
23 pub fn notify_one(&self) {
24 unsafe { self.inner.notify_one() };
27 /// Awakens all current waiters on this condition variable.
29 pub fn notify_all(&self) {
30 unsafe { self.inner.notify_all() };
33 /// Waits for a signal on the specified mutex.
35 /// Behavior is undefined if the mutex is not locked by the current thread.
37 /// May panic if used with more than one mutex.
39 pub unsafe fn wait(&self, mutex: &MovableMutex) {
40 self.check.verify(mutex);
41 self.inner.wait(mutex.raw())
44 /// Waits for a signal on the specified mutex with a timeout duration
45 /// specified by `dur` (a relative time into the future).
47 /// Behavior is undefined if the mutex is not locked by the current thread.
49 /// May panic if used with more than one mutex.
51 pub unsafe fn wait_timeout(&self, mutex: &MovableMutex, dur: Duration) -> bool {
52 self.check.verify(mutex);
53 self.inner.wait_timeout(mutex.raw(), dur)