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.
18 pub const fn new() -> Self {
19 Self { inner: imp::MovableCondvar::new(), check: CondvarCheck::new() }
22 /// Signals one waiter on this condition variable to wake up.
24 pub fn notify_one(&self) {
25 unsafe { self.inner.notify_one() };
28 /// Awakens all current waiters on this condition variable.
30 pub fn notify_all(&self) {
31 unsafe { self.inner.notify_all() };
34 /// Waits for a signal on the specified mutex.
36 /// Behavior is undefined if the mutex is not locked by the current thread.
38 /// May panic if used with more than one mutex.
40 pub unsafe fn wait(&self, mutex: &MovableMutex) {
41 self.check.verify(mutex);
42 self.inner.wait(mutex.raw())
45 /// Waits for a signal on the specified mutex with a timeout duration
46 /// specified by `dur` (a relative time into the future).
48 /// Behavior is undefined if the mutex is not locked by the current thread.
50 /// May panic if used with more than one mutex.
52 pub unsafe fn wait_timeout(&self, mutex: &MovableMutex, dur: Duration) -> bool {
53 self.check.verify(mutex);
54 self.inner.wait_timeout(mutex.raw(), dur)