diff --git a/Cargo.lock b/Cargo.lock index fd65ed8d4a2d6..1082e8f2370ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1972,9 +1972,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.116" +version = "0.2.119" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "565dbd88872dbe4cc8a46e527f26483c1d1f7afa6b884a3bd6cd893d4f98da74" +checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" dependencies = [ "rustc-std-workspace-core", ] diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 146096535dbbe..c9574ed54f771 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -15,7 +15,7 @@ cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] } panic_unwind = { path = "../panic_unwind", optional = true } panic_abort = { path = "../panic_abort" } core = { path = "../core" } -libc = { version = "0.2.116", default-features = false, features = ['rustc-dep-of-std'] } +libc = { version = "0.2.119", default-features = false, features = ['rustc-dep-of-std'] } compiler_builtins = { version = "0.1.69" } profiler_builtins = { path = "../profiler_builtins", optional = true } unwind = { path = "../unwind" } diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs index 59ddd1aa92f81..9a8634aa33327 100644 --- a/library/std/src/sys/unix/time.rs +++ b/library/std/src/sys/unix/time.rs @@ -114,7 +114,7 @@ impl Hash for Timespec { } } -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(any(all(target_os = "macos", not(target_arch = "aarch64")), target_os = "ios"))] mod inner { use crate::fmt; use crate::sync::atomic::{AtomicU64, Ordering}; @@ -263,7 +263,7 @@ mod inner { } } -#[cfg(not(any(target_os = "macos", target_os = "ios")))] +#[cfg(not(any(all(target_os = "macos", not(target_arch = "aarch64")), target_os = "ios")))] mod inner { use crate::fmt; use crate::sys::cvt; @@ -285,7 +285,11 @@ mod inner { impl Instant { pub fn now() -> Instant { - Instant { t: now(libc::CLOCK_MONOTONIC) } + #[cfg(target_os = "macos")] + const clock_id: clock_t = libc::CLOCK_UPTIME_RAW; + #[cfg(not(target_os = "macos"))] + const clock_id: clock_t = libc::CLOCK_MONOTONIC; + Instant { t: now(clock_id) } } pub fn checked_sub_instant(&self, other: &Instant) -> Option { @@ -343,10 +347,12 @@ mod inner { } } - #[cfg(not(any(target_os = "dragonfly", target_os = "espidf")))] + #[cfg(not(any(target_os = "dragonfly", target_os = "espidf", target_os = "macos")))] pub type clock_t = libc::c_int; #[cfg(any(target_os = "dragonfly", target_os = "espidf"))] pub type clock_t = libc::c_ulong; + #[cfg(target_os = "macos")] + pub type clock_t = libc::clockid_t; fn now(clock: clock_t) -> Timespec { let mut t = Timespec { t: libc::timespec { tv_sec: 0, tv_nsec: 0 } }; diff --git a/library/std/src/time/tests.rs b/library/std/src/time/tests.rs index d1a69ff8697c6..56a16465d7be8 100644 --- a/library/std/src/time/tests.rs +++ b/library/std/src/time/tests.rs @@ -12,6 +12,14 @@ macro_rules! assert_almost_eq { }}; } +#[test] +fn macos_resolution_regression() { + let t0 = Instant::now(); + let t1 = t0 + Duration::from_nanos(50); + let d = t1 - t0; + assert_eq!(t0 + d, t1); +} + #[test] fn instant_monotonic() { let a = Instant::now();