Skip to content

Commit 4fbd71c

Browse files
committed
Return timeout status in futex_wait.
1 parent cd2da4d commit 4fbd71c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

library/std/src/sys/unix/futex.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::sync::atomic::AtomicI32;
1212
use crate::time::Duration;
1313

1414
#[cfg(any(target_os = "linux", target_os = "android"))]
15-
pub fn futex_wait(futex: &AtomicI32, expected: i32, timeout: Option<Duration>) {
15+
pub fn futex_wait(futex: &AtomicI32, expected: i32, timeout: Option<Duration>) -> bool {
1616
let timespec = timeout.and_then(|d| {
1717
Some(libc::timespec {
1818
// 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>) {
2121
tv_nsec: d.subsec_nanos() as _,
2222
})
2323
});
24-
unsafe {
24+
let r = unsafe {
2525
libc::syscall(
2626
libc::SYS_futex,
2727
futex as *const AtomicI32,
2828
libc::FUTEX_WAIT | libc::FUTEX_PRIVATE_FLAG,
2929
expected,
3030
timespec.as_ref().map_or(null(), |d| d as *const libc::timespec),
31-
);
32-
}
31+
)
32+
};
33+
!(r < 0 && super::os::errno() == libc::ETIMEDOUT)
3334
}
3435

3536
#[cfg(target_os = "emscripten")]

0 commit comments

Comments
 (0)