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