Skip to content

Commit c9ae3fe

Browse files
committed
Explicitly use CLOCK_MONOTONIC in futex_wait.
Instant might be changed to use CLOCK_BOOTTIME at some point.
1 parent 23badeb commit c9ae3fe

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ use crate::time::Duration;
99

1010
#[cfg(any(target_os = "linux", target_os = "android"))]
1111
pub fn futex_wait(futex: &AtomicI32, expected: i32, timeout: Option<Duration>) -> bool {
12-
use super::time::Instant;
12+
use super::time::Timespec;
1313
use crate::ptr::null;
1414
use crate::sync::atomic::Ordering::Relaxed;
1515

1616
// Calculate the timeout as an absolute timespec.
1717
let timespec =
18-
timeout.and_then(|d| Some(Instant::now().checked_add_duration(&d)?.as_timespec()));
18+
timeout.and_then(|d| Some(Timespec::now(libc::CLOCK_MONOTONIC).checked_add_duration(&d)?));
1919

2020
loop {
2121
// No need to wait if the value already changed.
@@ -31,7 +31,7 @@ pub fn futex_wait(futex: &AtomicI32, expected: i32, timeout: Option<Duration>) -
3131
futex as *const AtomicI32,
3232
libc::FUTEX_WAIT_BITSET | libc::FUTEX_PRIVATE_FLAG,
3333
expected,
34-
timespec.as_ref().map_or(null(), |d| d as *const libc::timespec),
34+
timespec.as_ref().map_or(null(), |t| &t.t as *const libc::timespec),
3535
null::<u32>(), // This argument is unused for FUTEX_WAIT_BITSET.
3636
!0u32, // A full bitmask, to make it behave like a regular FUTEX_WAIT.
3737
)

0 commit comments

Comments
 (0)