@@ -19,8 +19,8 @@ cfg_if::cfg_if! {
19
19
// correctly implemented in Linux and due to backwards compatibility
20
20
// concerns they were never able to fix it properly. Thus `CLOCK_MONOTONIC`
21
21
// means uptime on Linux whereas on other Unixes it means real time (the BSD
22
- // family). So the solution is to use this on all operating systems that are
23
- // based on the Linux kernel .
22
+ // family). As a solution the Linux kernel provides `CLOCK_BOOTTIME` to
23
+ // measure the real time .
24
24
//
25
25
// # macOS and iOS
26
26
//
@@ -36,26 +36,19 @@ cfg_if::cfg_if! {
36
36
//
37
37
// # Fuchsia
38
38
//
39
- // Fuchsia is based on the new Zircon kernel. It has two functions for
40
- // querying the time:
39
+ // Fuchsia is based on the new Zircon kernel. It has `zx_clock_get_boot` to
40
+ // query the real time and `zx_clock_get_monotonic` to query the uptime.
41
41
//
42
- // zx_clock_get:
43
- // https://fuchsia.dev/fuchsia-src/reference/syscalls/clock_get
44
- // zx_clock_get_monotonic:
45
- // https://fuchsia.dev/fuchsia-src/reference/syscalls/clock_get_monotonic
42
+ // https://fuchsia.dev/reference/syscalls/clock_get_boot
46
43
//
47
- // `zx_clock_get_monotonic` specifically calls out that it `does not adjust
48
- // during sleep` which seems to mean that it doesn't count the time the OS
49
- // is suspended. This is further evidenced by their libc implementation not
50
- // treating `CLOCK_BOOTTIME` differently and a bug ticket being linked
51
- // there:
52
- // https://cs.opensource.google/fuchsia/fuchsia/+/main:zircon/third_party/ulib/musl/src/time/clock_gettime.c;l=40;drc=35e7a15cb21e16f0705560e5812b7a045d42c8a5
44
+ // They are supposed to be available through `CLOCK_BOOTTIME` and
45
+ // `CLOCK_MONOTONIC` respectively, just like on Linux.
53
46
//
54
47
// # WASI
55
48
//
56
49
// https://github.com/WebAssembly/WASI/blob/5ab83a68d4eb4f218a898ed03b963b7393caaedc/phases/snapshot/docs.md#variant-cases
57
50
//
58
- // WASI seems to underspecify its `monotonic` a bit, but says that it `is
51
+ // WASI seems to under specify its `monotonic` a bit, but says that it `is
59
52
// defined as a clock measuring real time`, making it sound like a compliant
60
53
// implementation should measure the time the OS is suspended as well.
61
54
//
@@ -98,10 +91,14 @@ cfg_if::cfg_if! {
98
91
// the Linux kernel and instead has its own implementation in JavaScript
99
92
// where it actually errors out on `CLOCK_BOOTTIME`:
100
93
// https://github.com/emscripten-core/emscripten/blob/9bdb310b89472a0f4d64f36e4a79273d8dc7fa98/system/lib/libc/emscripten_time.c#L50-L57
94
+ //
95
+ // And we add Fuchsia to this list as it's based on the Zircon kernel which
96
+ // uses `CLOCK_BOOTTIME` in the same way as Linux.
101
97
if #[ cfg( any(
102
98
target_os = "linux" ,
103
99
target_os = "l4re" ,
104
100
target_os = "android" ,
101
+ target_os = "fuchsia" ,
105
102
) ) ] {
106
103
use core:: { mem:: MaybeUninit , ops:: Sub } ;
107
104
0 commit comments