1use fuchsia_sync::MutexGuard;
6
7pub struct CondVar {
10 inner: fuchsia_sync::Condvar,
11}
12
13pub struct WaitToken(());
16
17pub trait WaitableMutexGuard<'a, T> {
18 fn inner_guard(&mut self, token: WaitToken) -> &mut MutexGuard<'a, T>;
19}
20
21impl<'a, T> WaitableMutexGuard<'a, T> for MutexGuard<'a, T> {
22 fn inner_guard(&mut self, _token: WaitToken) -> &mut MutexGuard<'a, T> {
23 self
24 }
25}
26
27impl CondVar {
28 #[inline]
29 pub const fn new() -> Self {
30 Self { inner: fuchsia_sync::Condvar::new() }
31 }
32
33 pub fn wait<'a, T: 'a, G: WaitableMutexGuard<'a, T>>(&self, guard: &mut G) {
35 self.inner.wait(guard.inner_guard(WaitToken(())));
36 }
37
38 pub fn notify_one(&self) {
40 self.inner.notify_one();
41 }
42
43 pub fn notify_all(&self) {
45 self.inner.notify_all();
46 }
47}
48
49impl Default for CondVar {
50 fn default() -> Self {
51 Self::new()
52 }
53}
54
55impl std::fmt::Debug for CondVar {
56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 f.debug_struct("CondVar").finish()
58 }
59}