diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/rustix/src/time | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/time')
-rw-r--r-- | vendor/rustix/src/time/clock.rs | 56 | ||||
-rw-r--r-- | vendor/rustix/src/time/mod.rs | 20 | ||||
-rw-r--r-- | vendor/rustix/src/time/timerfd.rs | 42 |
3 files changed, 118 insertions, 0 deletions
diff --git a/vendor/rustix/src/time/clock.rs b/vendor/rustix/src/time/clock.rs new file mode 100644 index 000000000..32d888749 --- /dev/null +++ b/vendor/rustix/src/time/clock.rs @@ -0,0 +1,56 @@ +use crate::{imp, io}; + +pub use imp::time::types::{Nsecs, Secs, Timespec}; + +/// `clockid_t` +#[cfg(any(not(target_os = "wasi")))] +pub use imp::time::types::{ClockId, DynamicClockId}; + +/// `clock_getres(id)`—Returns the resolution of a clock. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html +/// [Linux]: https://man7.org/linux/man-pages/man2/clock_getres.2.html +#[cfg(any(not(any(target_os = "redox", target_os = "wasi"))))] +#[inline] +#[must_use] +pub fn clock_getres(id: ClockId) -> Timespec { + imp::time::syscalls::clock_getres(id) +} + +/// `clock_gettime(id)`—Returns the current value of a clock. +/// +/// This function uses `ClockId` which only contains clocks which are known to +/// always be supported at runtime, allowing this function to be infallible. +/// For a greater set of clocks and dynamic clock support, see +/// [`clock_gettime_dynamic`]. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html +/// [Linux]: https://man7.org/linux/man-pages/man2/clock_gettime.2.html +#[cfg(not(target_os = "wasi"))] +#[inline] +#[must_use] +pub fn clock_gettime(id: ClockId) -> Timespec { + imp::time::syscalls::clock_gettime(id) +} + +/// Like [`clock_gettime`] but with support for dynamic clocks. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html +/// [Linux]: https://man7.org/linux/man-pages/man2/clock_gettime.2.html +#[cfg(not(target_os = "wasi"))] +#[inline] +pub fn clock_gettime_dynamic(id: DynamicClockId<'_>) -> io::Result<Timespec> { + imp::time::syscalls::clock_gettime_dynamic(id) +} diff --git a/vendor/rustix/src/time/mod.rs b/vendor/rustix/src/time/mod.rs new file mode 100644 index 000000000..ca5b2b2dd --- /dev/null +++ b/vendor/rustix/src/time/mod.rs @@ -0,0 +1,20 @@ +//! Time-related operations. + +mod clock; +#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] +#[cfg(feature = "time")] +mod timerfd; + +// TODO: Convert WASI'S clock APIs to use handles rather than ambient clock +// identifiers, update `wasi-libc`, and then add support in `rustix`. +#[cfg(not(any(target_os = "redox", target_os = "wasi")))] +pub use clock::clock_getres; +#[cfg(not(target_os = "wasi"))] +pub use clock::{clock_gettime, clock_gettime_dynamic, ClockId, DynamicClockId}; +pub use clock::{Nsecs, Secs, Timespec}; +#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] +#[cfg(feature = "time")] +pub use timerfd::{ + timerfd_create, timerfd_gettime, timerfd_settime, Itimerspec, TimerfdClockId, TimerfdFlags, + TimerfdTimerFlags, +}; diff --git a/vendor/rustix/src/time/timerfd.rs b/vendor/rustix/src/time/timerfd.rs new file mode 100644 index 000000000..5abe6ff52 --- /dev/null +++ b/vendor/rustix/src/time/timerfd.rs @@ -0,0 +1,42 @@ +use crate::fd::AsFd; +use crate::imp; +use crate::io::{self, OwnedFd}; + +pub use imp::time::types::{Itimerspec, TimerfdClockId, TimerfdFlags, TimerfdTimerFlags}; + +/// `timerfd_create(clockid, flags)`—Create a timer. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_create.2.html +#[inline] +pub fn timerfd_create(clockid: TimerfdClockId, flags: TimerfdFlags) -> io::Result<OwnedFd> { + imp::time::syscalls::timerfd_create(clockid, flags) +} + +/// `timerfd_settime(clockid, flags, new_value)`—Set the time on a timer. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_settime.2.html +#[inline] +pub fn timerfd_settime<Fd: AsFd>( + fd: Fd, + flags: TimerfdTimerFlags, + new_value: &Itimerspec, +) -> io::Result<Itimerspec> { + imp::time::syscalls::timerfd_settime(fd.as_fd(), flags, new_value) +} + +/// `timerfd_gettime(clockid, flags)`—Query a timer. +/// +/// # References +/// - [Linux] +/// +/// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_gettime.2.html +#[inline] +pub fn timerfd_gettime<Fd: AsFd>(fd: Fd) -> io::Result<Itimerspec> { + imp::time::syscalls::timerfd_gettime(fd.as_fd()) +} |