//! `sync` on WASI: one thread, which nobody can wake.
use core::sync::atomic::{AtomicU32, Ordering};
use core::time::Duration;
use crate::{ErrorKind, Result};
/// Whether the wait ended otherwise than by its timeout.
pub(crate) fn wait(atomic: &AtomicU32, expected: u32, timeout: Option<Duration>) -> Result<bool> {
if atomic.load(Ordering::SeqCst) != expected {
return Ok(true);
}
match timeout {
// The wait could never end.
None => Err(ErrorKind::Deadlock.into()),
Some(timeout) => {
if !timeout.is_zero() {
crate::sys::time::sleep(timeout)?;
}
Ok(false)
}
}
}
pub(crate) fn wake(_atomic: &AtomicU32, _all: bool) {}