Skip to content

Commit 0e6d83d

Browse files
authored
fix: switch to clock_gettime(3) for macOS/iOS for monotonic clock (#97)
This fixes an issue where on M1 (and presumably M2/M3) hardware, the usage of mach_absolute_time() resulted in undermeasuring the passage of time when compared to std::time::Instant. Now we read from the monotonic clock (using clock_gettime, but conceptually the same as calling mach_continuous_time()) which properly tracks the passage of time regardless of device sleep, frequency, etc.
1 parent cc2c4b1 commit 0e6d83d

File tree

5 files changed

+10
-49
lines changed

5 files changed

+10
-49
lines changed

Diff for: .github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
strategy:
3232
matrix:
3333
rust_version: ['1.60.0', 'stable', 'nightly']
34-
os: [ubuntu-latest, windows-latest, macOS-latest]
34+
os: [ubuntu-20.04, ubuntu-22.04, macOS-11, macOS-12, windows-2019, windows-2022]
3535
steps:
3636
- uses: actions/checkout@v3
3737
- name: Install Rust ${{ matrix.rust_version }}

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

99
## [Unreleased] - ReleaseDate
1010

11+
### Fixed
12+
13+
- Fixed an issue with the monotonic clock for macOS/iOS where it would undermeasure time compared to
14+
what would be measured by `std::time::Instant` due to using a clock source that did not account
15+
for device sleep.
16+
1117
## [0.12.1] - 2023-10-31
1218

1319
### Fixed

Diff for: Cargo.toml

+1-7
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,9 @@ raw-cpuid = "11.0"
4747
[target.'cfg(target_arch = "x86_64")'.dependencies]
4848
raw-cpuid = "11.0"
4949

50-
[target.'cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows", target_arch = "wasm32")))'.dependencies]
50+
[target.'cfg(not(any(target_os = "windows", target_arch = "wasm32")))'.dependencies]
5151
libc = "0.2"
5252

53-
[target.'cfg(target_os = "macos")'.dependencies]
54-
mach2 = "0.4"
55-
56-
[target.'cfg(target_os = "ios")'.dependencies]
57-
mach2 = "0.4"
58-
5953
[target.'cfg(target_os = "windows")'.dependencies]
6054
winapi = { version = "0.3", features = ["profileapi"] }
6155

Diff for: src/clocks/monotonic/macos.rs

-24
This file was deleted.

Diff for: src/clocks/monotonic/mod.rs

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
#[cfg(any(target_os = "macos", target_os = "ios"))]
2-
mod macos;
3-
#[cfg(any(target_os = "macos", target_os = "ios"))]
4-
pub use self::macos::Monotonic;
5-
61
#[cfg(target_os = "windows")]
72
mod windows;
83
#[cfg(target_os = "windows")]
@@ -13,17 +8,7 @@ mod wasm;
138
#[cfg(target_arch = "wasm32")]
149
pub use self::wasm::Monotonic;
1510

16-
#[cfg(not(any(
17-
target_os = "macos",
18-
target_os = "ios",
19-
target_os = "windows",
20-
target_arch = "wasm32"
21-
)))]
11+
#[cfg(not(any(target_os = "windows", target_arch = "wasm32")))]
2212
mod unix;
23-
#[cfg(not(any(
24-
target_os = "macos",
25-
target_os = "ios",
26-
target_os = "windows",
27-
target_arch = "wasm32"
28-
)))]
13+
#[cfg(not(any(target_os = "windows", target_arch = "wasm32")))]
2914
pub use self::unix::Monotonic;

0 commit comments

Comments
 (0)