diff --git a/simu/src/wait.rs b/simu/src/wait.rs new file mode 100644 index 0000000..44dc885 --- /dev/null +++ b/simu/src/wait.rs @@ -0,0 +1,35 @@ +use std::sync::atomic::AtomicU32; + +#[cfg(feature = "futex")] +use wait_on_address::AtomicWait; + +pub trait WaitOnAtomic { + fn wait(&self, v: u32); + fn signal(&self); +} + +#[cfg(feature = "futex")] +impl WaitOnAtomic for AtomicU32 { + fn wait(&self, v: u32) { + ::wait(self, v); + } + + fn signal(&self) { + self.notify_one(); + } +} + +#[cfg(not(feature = "futex"))] +impl WaitOnAtomic for AtomicU32 { + fn wait(&self, v: u32) { + while self.load(std::sync::atomic::Ordering::Acquire) == v { + use std::{thread::sleep, time::Duration}; + + sleep(Duration::from_micros(500)); + } + } + + fn signal(&self) { + // + } +}