1 #![cfg(any(target_os = "linux", target_os = "android"))]
3 use crate::convert::TryInto;
5 use crate::sync::atomic::AtomicI32;
6 use crate::time::Duration;
8 pub fn futex_wait(futex: &AtomicI32, expected: i32, timeout: Option<Duration>) {
9 let timespec = timeout.and_then(|d| {
11 // Sleep forever if the timeout is longer than fits in a timespec.
12 tv_sec: d.as_secs().try_into().ok()?,
13 // This conversion never truncates, as subsec_nanos is always <1e9.
14 tv_nsec: d.subsec_nanos() as _,
20 futex as *const AtomicI32,
21 libc::FUTEX_WAIT | libc::FUTEX_PRIVATE_FLAG,
23 timespec.as_ref().map_or(null(), |d| d as *const libc::timespec),
28 pub fn futex_wake(futex: &AtomicI32) {
32 futex as *const AtomicI32,
33 libc::FUTEX_WAKE | libc::FUTEX_PRIVATE_FLAG,