Skip to content

Commit

Permalink
Use CLOCK_BOOTTIME for Instant in Fuchsia/Android
Browse files Browse the repository at this point in the history
Fuchsia and Android both want Instants to progress during periods of
suspension, and thus must use CLOCK_BOOTTIME as the backing reference
clock.
  • Loading branch information
Anirudh Mathukumilli committed Oct 29, 2024
1 parent e473783 commit 88eafa4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion library/std/src/sys/pal/unix/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ impl Instant {
// we preserve this value domain out of an abundance of caution.
#[cfg(target_vendor = "apple")]
const clock_id: libc::clockid_t = libc::CLOCK_UPTIME_RAW;
#[cfg(not(target_vendor = "apple"))]
// Instant is intended to progress forward during periods of suspension
// in both Android and Fuchsia, and therefore uses CLOCK_BOOTTIME.
#[cfg(any(target_os = "android", target_os = "fuchsia"))]
const clock_id: libc::clockid_t = libc::CLOCK_BOOTTIME;
#[cfg(not(any(target_vendor = "apple", target_os = "fuchsia", target_os = "android")))]
const clock_id: libc::clockid_t = libc::CLOCK_MONOTONIC;
Instant { t: Timespec::now(clock_id) }
}
Expand Down

0 comments on commit 88eafa4

Please sign in to comment.