summaryrefslogtreecommitdiff
path: root/src/time.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/time.rs')
-rw-r--r--src/time.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/time.rs b/src/time.rs
index 91ed7c6d..959769f4 100644
--- a/src/time.rs
+++ b/src/time.rs
@@ -6,6 +6,7 @@ use crate::sys::time::TimeSpec;
target_os = "android",
target_os = "emscripten",
))]
+#[cfg(feature = "process")]
use crate::unistd::Pid;
use crate::{Errno, Result};
use libc::{self, clockid_t};
@@ -24,6 +25,8 @@ impl ClockId {
ClockId(clk_id)
}
+ feature! {
+ #![feature = "process"]
/// Returns `ClockId` of a `pid` CPU-time clock
#[cfg(any(
target_os = "freebsd",
@@ -32,12 +35,15 @@ impl ClockId {
target_os = "android",
target_os = "emscripten",
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn pid_cpu_clock_id(pid: Pid) -> Result<Self> {
clock_getcpuclockid(pid)
}
+ }
/// Returns resolution of the clock id
#[cfg(not(target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn res(self) -> Result<TimeSpec> {
clock_getres(self)
}
@@ -54,6 +60,7 @@ impl ClockId {
target_os = "redox",
target_os = "hermit",
)))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn set_time(self, timespec: TimeSpec) -> Result<()> {
clock_settime(self, timespec)
}
@@ -69,6 +76,7 @@ impl ClockId {
target_os = "fuchsia",
target_os = "linux"
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_BOOTTIME: ClockId = ClockId(libc::CLOCK_BOOTTIME);
#[cfg(any(
target_os = "android",
@@ -76,6 +84,7 @@ impl ClockId {
target_os = "fuchsia",
target_os = "linux"
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_BOOTTIME_ALARM: ClockId = ClockId(libc::CLOCK_BOOTTIME_ALARM);
pub const CLOCK_MONOTONIC: ClockId = ClockId(libc::CLOCK_MONOTONIC);
#[cfg(any(
@@ -84,10 +93,13 @@ impl ClockId {
target_os = "fuchsia",
target_os = "linux"
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_MONOTONIC_COARSE: ClockId = ClockId(libc::CLOCK_MONOTONIC_COARSE);
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_MONOTONIC_FAST: ClockId = ClockId(libc::CLOCK_MONOTONIC_FAST);
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_MONOTONIC_PRECISE: ClockId = ClockId(libc::CLOCK_MONOTONIC_PRECISE);
#[cfg(any(
target_os = "android",
@@ -95,6 +107,7 @@ impl ClockId {
target_os = "fuchsia",
target_os = "linux"
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_MONOTONIC_RAW: ClockId = ClockId(libc::CLOCK_MONOTONIC_RAW);
#[cfg(any(
target_os = "android",
@@ -107,8 +120,10 @@ impl ClockId {
target_os = "redox",
target_os = "linux"
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_PROCESS_CPUTIME_ID: ClockId = ClockId(libc::CLOCK_PROCESS_CPUTIME_ID);
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_PROF: ClockId = ClockId(libc::CLOCK_PROF);
pub const CLOCK_REALTIME: ClockId = ClockId(libc::CLOCK_REALTIME);
#[cfg(any(
@@ -117,6 +132,7 @@ impl ClockId {
target_os = "fuchsia",
target_os = "linux"
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_REALTIME_ALARM: ClockId = ClockId(libc::CLOCK_REALTIME_ALARM);
#[cfg(any(
target_os = "android",
@@ -124,18 +140,23 @@ impl ClockId {
target_os = "fuchsia",
target_os = "linux"
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_REALTIME_COARSE: ClockId = ClockId(libc::CLOCK_REALTIME_COARSE);
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_REALTIME_FAST: ClockId = ClockId(libc::CLOCK_REALTIME_FAST);
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_REALTIME_PRECISE: ClockId = ClockId(libc::CLOCK_REALTIME_PRECISE);
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_SECOND: ClockId = ClockId(libc::CLOCK_SECOND);
#[cfg(any(
target_os = "emscripten",
target_os = "fuchsia",
all(target_os = "linux", target_env = "musl")
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_SGI_CYCLE: ClockId = ClockId(libc::CLOCK_SGI_CYCLE);
#[cfg(any(
target_os = "android",
@@ -143,6 +164,7 @@ impl ClockId {
target_os = "fuchsia",
target_os = "linux"
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_TAI: ClockId = ClockId(libc::CLOCK_TAI);
#[cfg(any(
target_os = "android",
@@ -154,14 +176,19 @@ impl ClockId {
target_os = "dragonfly",
target_os = "linux"
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_THREAD_CPUTIME_ID: ClockId = ClockId(libc::CLOCK_THREAD_CPUTIME_ID);
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_UPTIME: ClockId = ClockId(libc::CLOCK_UPTIME);
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_UPTIME_FAST: ClockId = ClockId(libc::CLOCK_UPTIME_FAST);
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_UPTIME_PRECISE: ClockId = ClockId(libc::CLOCK_UPTIME_PRECISE);
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub const CLOCK_VIRTUAL: ClockId = ClockId(libc::CLOCK_VIRTUAL);
}
@@ -186,6 +213,7 @@ impl std::fmt::Display for ClockId {
/// Get the resolution of the specified clock, (see
/// [clock_getres(2)](https://pubs.opengroup.org/onlinepubs/7908799/xsh/clock_getres.html)).
#[cfg(not(target_os = "redox"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn clock_getres(clock_id: ClockId) -> Result<TimeSpec> {
let mut c_time: MaybeUninit<libc::timespec> = MaybeUninit::uninit();
let ret = unsafe { libc::clock_getres(clock_id.as_raw(), c_time.as_mut_ptr()) };
@@ -213,6 +241,7 @@ pub fn clock_gettime(clock_id: ClockId) -> Result<TimeSpec> {
target_os = "redox",
target_os = "hermit",
)))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn clock_settime(clock_id: ClockId, timespec: TimeSpec) -> Result<()> {
let ret = unsafe { libc::clock_settime(clock_id.as_raw(), timespec.as_ref()) };
Errno::result(ret).map(drop)
@@ -227,6 +256,8 @@ pub fn clock_settime(clock_id: ClockId, timespec: TimeSpec) -> Result<()> {
target_os = "android",
target_os = "emscripten",
))]
+#[cfg(feature = "process")]
+#[cfg_attr(docsrs, doc(cfg(feature = "process")))]
pub fn clock_getcpuclockid(pid: Pid) -> Result<ClockId> {
let mut clk_id: MaybeUninit<libc::clockid_t> = MaybeUninit::uninit();
let ret = unsafe { libc::clock_getcpuclockid(pid.into(), clk_id.as_mut_ptr()) };