1use crate::backend::c;
2use crate::fd::BorrowedFd;
3
4/// `CLOCK_*` constants for use with [`clock_gettime`].
5///
6/// These constants are always supported at runtime, so `clock_gettime` never
7/// has to fail with `INVAL` due to an unsupported clock. See
8/// [`DynamicClockId`] for a greater set of clocks, with the caveat that not
9/// all of them are always supported.
10///
11/// [`clock_gettime`]: crate::time::clock_gettime
12#[cfg(not(any(apple, target_os = "wasi")))]
13#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
14#[cfg_attr(not(any(target_os = "aix", target_os = "dragonfly")), repr(i32))]
15#[cfg_attr(target_os = "dragonfly", repr(u64))]
16#[cfg_attr(target_os = "aix", repr(i64))]
17#[non_exhaustive]
18pub enum ClockId {
19 /// `CLOCK_REALTIME`
20 #[doc(alias = "CLOCK_REALTIME")]
21 Realtime = bitcast!(c::CLOCK_REALTIME),
22
23 /// `CLOCK_MONOTONIC`
24 #[doc(alias = "CLOCK_MONOTONIC")]
25 Monotonic = bitcast!(c::CLOCK_MONOTONIC),
26
27 /// `CLOCK_UPTIME`
28 #[cfg(any(freebsdlike, target_os = "openbsd"))]
29 #[doc(alias = "CLOCK_UPTIME")]
30 Uptime = c::CLOCK_UPTIME,
31
32 /// `CLOCK_PROCESS_CPUTIME_ID`
33 #[cfg(not(any(
34 solarish,
35 target_os = "netbsd",
36 target_os = "redox",
37 target_os = "vita"
38 )))]
39 #[doc(alias = "CLOCK_PROCESS_CPUTIME_ID")]
40 ProcessCPUTime = c::CLOCK_PROCESS_CPUTIME_ID,
41
42 /// `CLOCK_THREAD_CPUTIME_ID`
43 #[cfg(not(any(
44 solarish,
45 target_os = "netbsd",
46 target_os = "redox",
47 target_os = "vita"
48 )))]
49 #[doc(alias = "CLOCK_THREAD_CPUTIME_ID")]
50 ThreadCPUTime = c::CLOCK_THREAD_CPUTIME_ID,
51
52 /// `CLOCK_REALTIME_COARSE`
53 #[cfg(any(linux_kernel, target_os = "freebsd"))]
54 #[doc(alias = "CLOCK_REALTIME_COARSE")]
55 RealtimeCoarse = c::CLOCK_REALTIME_COARSE,
56
57 /// `CLOCK_MONOTONIC_COARSE`
58 #[cfg(any(linux_kernel, target_os = "freebsd"))]
59 #[doc(alias = "CLOCK_MONOTONIC_COARSE")]
60 MonotonicCoarse = c::CLOCK_MONOTONIC_COARSE,
61
62 /// `CLOCK_MONOTONIC_RAW`
63 #[cfg(linux_kernel)]
64 #[doc(alias = "CLOCK_MONOTONIC_RAW")]
65 MonotonicRaw = c::CLOCK_MONOTONIC_RAW,
66
67 /// `CLOCK_REALTIME_ALARM`
68 #[cfg(linux_kernel)]
69 #[doc(alias = "CLOCK_REALTIME_ALARM")]
70 RealtimeAlarm = bitcast!(c::CLOCK_REALTIME_ALARM),
71
72 /// `CLOCK_TAI`, available on Linux >= 3.10
73 #[cfg(all(linux_kernel, feature = "linux_4_11"))]
74 #[doc(alias = "CLOCK_TAI")]
75 Tai = bitcast!(c::CLOCK_TAI),
76
77 /// `CLOCK_BOOTTIME`
78 ///
79 /// On FreeBSD, use [`Self::Uptime`], as `CLOCK_BOOTTIME` is an alias for
80 /// `CLOCK_UPTIME`.
81 ///
82 /// [`Self::Uptime`]: https://docs.rs/rustix/*/x86_64-unknown-freebsd/rustix/time/enum.ClockId.html#variant.Uptime
83 #[cfg(any(linux_kernel, target_os = "fuchsia", target_os = "openbsd"))]
84 #[doc(alias = "CLOCK_BOOTTIME")]
85 Boottime = bitcast!(c::CLOCK_BOOTTIME),
86
87 /// `CLOCK_BOOTTIME_ALARM`
88 #[cfg(any(linux_kernel, target_os = "fuchsia"))]
89 #[doc(alias = "CLOCK_BOOTTIME_ALARM")]
90 BoottimeAlarm = bitcast!(c::CLOCK_BOOTTIME_ALARM),
91}
92
93/// `CLOCK_*` constants for use with [`clock_gettime`].
94///
95/// These constants are always supported at runtime, so `clock_gettime` never
96/// has to fail with `INVAL` due to an unsupported clock. See
97/// [`DynamicClockId`] for a greater set of clocks, with the caveat that not
98/// all of them are always supported.
99///
100/// [`clock_gettime`]: crate::time::clock_gettime
101#[cfg(apple)]
102#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
103#[repr(u32)]
104#[non_exhaustive]
105pub enum ClockId {
106 /// `CLOCK_REALTIME`
107 #[doc(alias = "CLOCK_REALTIME")]
108 Realtime = c::CLOCK_REALTIME,
109
110 /// `CLOCK_MONOTONIC`
111 #[doc(alias = "CLOCK_MONOTONIC")]
112 Monotonic = c::CLOCK_MONOTONIC,
113
114 /// `CLOCK_PROCESS_CPUTIME_ID`
115 #[doc(alias = "CLOCK_PROCESS_CPUTIME_ID")]
116 ProcessCPUTime = c::CLOCK_PROCESS_CPUTIME_ID,
117
118 /// `CLOCK_THREAD_CPUTIME_ID`
119 #[doc(alias = "CLOCK_THREAD_CPUTIME_ID")]
120 ThreadCPUTime = c::CLOCK_THREAD_CPUTIME_ID,
121}
122
123/// `CLOCK_*` constants for use with [`clock_gettime_dynamic`].
124///
125/// These constants may be unsupported at runtime, depending on the OS version,
126/// and `clock_gettime_dynamic` may fail with `INVAL`. See [`ClockId`] for
127/// clocks which are always supported at runtime.
128///
129/// [`clock_gettime_dynamic`]: crate::time::clock_gettime_dynamic
130#[cfg(not(target_os = "wasi"))]
131#[derive(Debug, Copy, Clone)]
132#[non_exhaustive]
133pub enum DynamicClockId<'a> {
134 /// `ClockId` values that are always supported at runtime.
135 Known(ClockId),
136
137 /// Linux dynamic clocks.
138 Dynamic(BorrowedFd<'a>),
139
140 /// `CLOCK_REALTIME_ALARM`
141 #[cfg(linux_kernel)]
142 #[doc(alias = "CLOCK_REALTIME_ALARM")]
143 RealtimeAlarm,
144
145 /// `CLOCK_TAI`, available on Linux >= 3.10
146 #[cfg(linux_kernel)]
147 #[doc(alias = "CLOCK_TAI")]
148 Tai,
149
150 /// `CLOCK_BOOTTIME`
151 #[cfg(any(
152 linux_kernel,
153 target_os = "freebsd",
154 target_os = "fuchsia",
155 target_os = "openbsd"
156 ))]
157 #[doc(alias = "CLOCK_BOOTTIME")]
158 Boottime,
159
160 /// `CLOCK_BOOTTIME_ALARM`
161 #[cfg(any(linux_kernel, target_os = "fuchsia"))]
162 #[doc(alias = "CLOCK_BOOTTIME_ALARM")]
163 BoottimeAlarm,
164}
165