diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/rustix-0.37.6/src/time | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix-0.37.6/src/time')
-rw-r--r-- | vendor/rustix-0.37.6/src/time/clock.rs | 78 | ||||
-rw-r--r-- | vendor/rustix-0.37.6/src/time/mod.rs | 13 | ||||
-rw-r--r-- | vendor/rustix-0.37.6/src/time/timerfd.rs | 41 |
3 files changed, 132 insertions, 0 deletions
diff --git a/vendor/rustix-0.37.6/src/time/clock.rs b/vendor/rustix-0.37.6/src/time/clock.rs new file mode 100644 index 000000000..1bf74d60b --- /dev/null +++ b/vendor/rustix-0.37.6/src/time/clock.rs @@ -0,0 +1,78 @@ +use crate::{backend, io}; + +pub use backend::time::types::{Nsecs, Secs, Timespec}; + +/// `clockid_t` +#[cfg(not(target_os = "wasi"))] +pub use backend::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(not(any(target_os = "redox", target_os = "wasi")))] +#[inline] +#[must_use] +pub fn clock_getres(id: ClockId) -> Timespec { + backend::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 { + backend::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> { + backend::time::syscalls::clock_gettime_dynamic(id) +} + +/// `clock_settime(id, timespec)`—Sets the current value of a settable clock. +/// +/// This fails with [`io::Errno::INVAL`] if the clock is not settable, and +/// [`io::Errno::ACCESS`] if the current process does not have permission to +/// set it. +/// +/// # References +/// - [POSIX] +/// - [Linux] +/// +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_settime.html +/// [Linux]: https://man7.org/linux/man-pages/man2/clock_settime.2.html +#[cfg(not(any( + target_os = "redox", + target_os = "wasi", + all(apple, not(target_os = "macos")) +)))] +#[inline] +pub fn clock_settime(id: ClockId, timespec: Timespec) -> io::Result<()> { + backend::time::syscalls::clock_settime(id, timespec) +} diff --git a/vendor/rustix-0.37.6/src/time/mod.rs b/vendor/rustix-0.37.6/src/time/mod.rs new file mode 100644 index 000000000..9a0dcb4d7 --- /dev/null +++ b/vendor/rustix-0.37.6/src/time/mod.rs @@ -0,0 +1,13 @@ +//! 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`. +pub use clock::*; +#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] +#[cfg(feature = "time")] +pub use timerfd::*; diff --git a/vendor/rustix-0.37.6/src/time/timerfd.rs b/vendor/rustix-0.37.6/src/time/timerfd.rs new file mode 100644 index 000000000..7f661f7d9 --- /dev/null +++ b/vendor/rustix-0.37.6/src/time/timerfd.rs @@ -0,0 +1,41 @@ +use crate::fd::{AsFd, OwnedFd}; +use crate::{backend, io}; + +pub use backend::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> { + backend::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> { + backend::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> { + backend::time::syscalls::timerfd_gettime(fd.as_fd()) +} |