Skip to content

Switch Instant to use CLOCK_BOOTTIME on Android. #145360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion library/std/src/sys/pal/unix/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ pub struct Instant {
impl Instant {
#[cfg(target_vendor = "apple")]
pub(crate) const CLOCK_ID: libc::clockid_t = libc::CLOCK_UPTIME_RAW;
#[cfg(not(target_vendor = "apple"))]
#[cfg(target_os = "android")]
pub(crate) const CLOCK_ID: libc::clockid_t = libc::CLOCK_BOOTTIME;
#[cfg(not(any(target_vendor = "apple", target_os = "android")))]
pub(crate) const CLOCK_ID: libc::clockid_t = libc::CLOCK_MONOTONIC;
pub fn now() -> Instant {
// https://www.manpagez.com/man/3/clock_gettime/
Expand All @@ -289,6 +291,9 @@ impl Instant {
//
// Instant on macos was historically implemented using mach_absolute_time;
// we preserve this value domain out of an abundance of caution.
//
// On Android, we use CLOCK_BOOTTIME because we want the duration between
// Instants to not be affected by suspends.
Instant { t: Timespec::now(Self::CLOCK_ID) }
}

Expand Down
Loading