3 use crate::sync::atomic::AtomicU32;
4 use crate::time::Duration;
6 pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -> bool {
7 // Calculate the timeout as a relative timespec.
9 // Overflows are rounded up to an infinite timeout (None).
10 let timespec = timeout.and_then(|dur| {
12 tv_sec: dur.as_secs().try_into().ok()?,
13 tv_nsec: dur.subsec_nanos().into(),
21 timespec.as_ref().map_or(null(), |t| t as *const abi::timespec),
22 abi::FUTEX_RELATIVE_TIMEOUT,
26 r != -abi::errno::ETIMEDOUT
30 pub fn futex_wake(futex: &AtomicU32) -> bool {
31 unsafe { abi::futex_wake(futex.as_mut_ptr(), 1) > 0 }
35 pub fn futex_wake_all(futex: &AtomicU32) {
37 abi::futex_wake(futex.as_mut_ptr(), i32::MAX);