diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2022-03-17 12:27:20 +0100 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2022-03-23 14:53:59 +0100 |
| commit | 4fbd71c94324965f5a3bcf01845b6da0d51076b7 (patch) | |
| tree | 3fc7eeacb1a6e812e61e8dbc31177204cc5ebe9c /library/std/src/sys/unix/futex.rs | |
| parent | cd2da4da379b060de7cb95e631e40e2227c1992b (diff) | |
| download | rust-4fbd71c94324965f5a3bcf01845b6da0d51076b7.tar.gz rust-4fbd71c94324965f5a3bcf01845b6da0d51076b7.zip | |
Return timeout status in futex_wait.
Diffstat (limited to 'library/std/src/sys/unix/futex.rs')
| -rw-r--r-- | library/std/src/sys/unix/futex.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/library/std/src/sys/unix/futex.rs b/library/std/src/sys/unix/futex.rs index 42ddc1d514e..22ba1a57fef 100644 --- a/library/std/src/sys/unix/futex.rs +++ b/library/std/src/sys/unix/futex.rs @@ -12,7 +12,7 @@ use crate::sync::atomic::AtomicI32; use crate::time::Duration; #[cfg(any(target_os = "linux", target_os = "android"))] -pub fn futex_wait(futex: &AtomicI32, expected: i32, timeout: Option<Duration>) { +pub fn futex_wait(futex: &AtomicI32, expected: i32, timeout: Option<Duration>) -> bool { let timespec = timeout.and_then(|d| { Some(libc::timespec { // Sleep forever if the timeout is longer than fits in a timespec. @@ -21,15 +21,16 @@ pub fn futex_wait(futex: &AtomicI32, expected: i32, timeout: Option<Duration>) { tv_nsec: d.subsec_nanos() as _, }) }); - unsafe { + let r = unsafe { libc::syscall( libc::SYS_futex, futex as *const AtomicI32, libc::FUTEX_WAIT | libc::FUTEX_PRIVATE_FLAG, expected, timespec.as_ref().map_or(null(), |d| d as *const libc::timespec), - ); - } + ) + }; + !(r < 0 && super::os::errno() == libc::ETIMEDOUT) } #[cfg(target_os = "emscripten")] |
