Skip to content

Commit c589d65

Browse files
committed
Add test and discussed fix
1 parent 30b3f35 commit c589d65

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,11 @@ mod inner {
149149
impl Instant {
150150
pub fn now() -> Instant {
151151
extern "C" {
152-
fn mach_absolute_time() -> u64;
152+
//fn mach_absolute_time() -> u64;
153+
fn clock_gettime_nsec_np(clock_type: i64) -> u64;
153154
}
154-
Instant { t: unsafe { mach_absolute_time() } }
155+
Instant { t: unsafe { clock_gettime_nsec_np(4) } }
156+
//Instant { t: unsafe { mach_absolute_time() } }
155157
}
156158

157159
pub fn checked_sub_instant(&self, other: &Instant) -> Option<Duration> {

library/std/src/time/tests.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ macro_rules! assert_almost_eq {
1212
}};
1313
}
1414

15+
#[test]
16+
#[cfg(all(target_arch = "aarch64", target_os = "macos"))]
17+
fn wtf() {
18+
let t0 = Instant::now();
19+
let t1 = t0 + Duration::from_nanos(50);
20+
let d = t1 - t0;
21+
dbg!(t0, t1, d);
22+
assert_eq!(t0 + d, t1);
23+
}
24+
1525
#[test]
1626
fn instant_monotonic() {
1727
let a = Instant::now();

0 commit comments

Comments
 (0)