Skip to content

Commit 3ab376d

Browse files
committed
use CLOCK_BOOTTIME in Instant::now
There was a discussion on #87907 that all platforms expect linux advance its monotonic timer if the system goes into a sleep state (e.g. suspend or hibernate). It was decided that CLOCK_BOOTTIME should be used on unix targets.
1 parent c372b14 commit 3ab376d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,13 @@ mod inner {
291291
pub fn now() -> Instant {
292292
#[cfg(target_os = "macos")]
293293
const clock_id: libc::clockid_t = libc::CLOCK_UPTIME_RAW;
294-
#[cfg(not(target_os = "macos"))]
294+
295+
#[cfg(target_os = "linux")]
296+
const clock_id: libc::clockid_t = libc::CLOCK_BOOTTIME;
297+
298+
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
295299
const clock_id: libc::clockid_t = libc::CLOCK_MONOTONIC;
300+
296301
Instant { t: Timespec::now(clock_id) }
297302
}
298303

0 commit comments

Comments
 (0)