reifydb_runtime/sync/condvar/
mod.rs1use std::time::Duration;
7
8use cfg_if::cfg_if;
9
10use crate::sync::mutex::MutexGuard;
11
12#[cfg(reifydb_target = "native")]
13pub mod native;
14#[cfg(reifydb_target = "wasm")]
15pub mod wasm;
16
17cfg_if! {
18 if #[cfg(reifydb_target = "native")] {
19 type CondvarInner = native::CondvarInner;
20 } else {
21 type CondvarInner = wasm::CondvarInner;
22 }
23}
24
25pub struct WaitTimeoutResult {
27 timed_out: bool,
28}
29
30impl WaitTimeoutResult {
31 #[inline]
33 pub fn timed_out(&self) -> bool {
34 self.timed_out
35 }
36}
37
38#[derive(Debug)]
40pub struct Condvar {
41 inner: CondvarInner,
42}
43
44impl Condvar {
45 #[inline]
47 pub fn new() -> Self {
48 Self {
49 inner: CondvarInner::new(),
50 }
51 }
52
53 #[inline]
55 pub fn wait<'a, T>(&self, guard: &mut MutexGuard<'a, T>) {
56 self.inner.wait(guard);
57 }
58
59 #[inline]
61 pub fn wait_for<'a, T>(&self, guard: &mut MutexGuard<'a, T>, timeout: Duration) -> WaitTimeoutResult {
62 let timed_out = self.inner.wait_for(guard, timeout);
63 WaitTimeoutResult {
64 timed_out,
65 }
66 }
67
68 #[inline]
70 pub fn notify_one(&self) {
71 self.inner.notify_one();
72 }
73
74 #[inline]
76 pub fn notify_all(&self) {
77 self.inner.notify_all();
78 }
79}
80
81impl Default for Condvar {
82 #[inline]
83 fn default() -> Self {
84 Self::new()
85 }
86}