| 1 |
use crate::fd::{AsFd, OwnedFd}; |
| 2 |
use crate::timespec::Timespec; |
| 3 |
use crate::{backend, io}; |
| 4 |
|
| 5 |
pub use backend::time::types::{TimerfdClockId, TimerfdFlags, TimerfdTimerFlags}; |
| 6 |
|
| 7 |
/// `struct itimerspec` for use with [`timerfd_gettime`] and |
| 8 |
/// [`timerfd_settime`]. |
| 9 |
/// |
| 10 |
/// [`timerfd_gettime`]: crate::time::timerfd_gettime |
| 11 |
/// [`timerfd_settime`]: crate::time::timerfd_settime |
| 12 |
#[derive(Debug, Clone)] |
| 13 |
pub struct Itimerspec { |
| 14 |
/// Interval between times. |
| 15 |
pub it_interval: Timespec, |
| 16 |
/// Value of the time. |
| 17 |
pub it_value: Timespec, |
| 18 |
} |
| 19 |
|
| 20 |
/// `timerfd_create(clockid, flags)`—Create a timer. |
| 21 |
/// |
| 22 |
/// For a higher-level API to timerfd functionality, see the [timerfd] crate. |
| 23 |
/// |
| 24 |
/// [timerfd]: https://crates.io/crates/timerfd |
| 25 |
/// |
| 26 |
/// # References |
| 27 |
/// - [Linux] |
| 28 |
/// - [FreeBSD] |
| 29 |
/// - [illumos] |
| 30 |
/// - [NetBSD] |
| 31 |
/// |
| 32 |
/// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_create.2.html |
| 33 |
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=timerfd_create&sektion=2 |
| 34 |
/// [illumos]: https://illumos.org/man/3C/timerfd_create |
| 35 |
/// [NetBSD]: https://man.netbsd.org/timerfd_create.2 |
| 36 |
#[inline] |
| 37 |
pub fn timerfd_create(clockid: TimerfdClockId, flags: TimerfdFlags) -> io::Result<OwnedFd> { |
| 38 |
backend::time::syscalls::timerfd_create(clockid, flags) |
| 39 |
} |
| 40 |
|
| 41 |
/// `timerfd_settime(clockid, flags, new_value)`—Set the time on a timer. |
| 42 |
/// |
| 43 |
/// # References |
| 44 |
/// - [Linux] |
| 45 |
/// - [FreeBSD] |
| 46 |
/// - [illumos] |
| 47 |
/// - [NetBSD] |
| 48 |
/// |
| 49 |
/// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_settime.2.html |
| 50 |
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=timerfd_settime&sektion=2 |
| 51 |
/// [illumos]: https://illumos.org/man/3C/timerfd_settime |
| 52 |
/// [NetBSD]: https://man.netbsd.org/timerfd_settime.2 |
| 53 |
#[inline] |
| 54 |
pub fn timerfd_settime<Fd: AsFd>( |
| 55 |
fd: Fd, |
| 56 |
flags: TimerfdTimerFlags, |
| 57 |
new_value: &Itimerspec, |
| 58 |
) -> io::Result<Itimerspec> { |
| 59 |
backend::time::syscalls::timerfd_settime(fd.as_fd(), flags, new_value) |
| 60 |
} |
| 61 |
|
| 62 |
/// `timerfd_gettime(clockid, flags)`—Query a timer. |
| 63 |
/// |
| 64 |
/// # References |
| 65 |
/// - [Linux] |
| 66 |
/// - [FreeBSD] |
| 67 |
/// - [illumos] |
| 68 |
/// - [NetBSD] |
| 69 |
/// |
| 70 |
/// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_gettime.2.html |
| 71 |
/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=timerfd_gettime&sektion=2 |
| 72 |
/// [illumos]: https://illumos.org/man/3C/timerfd_gettime |
| 73 |
/// [NetBSD]: https://man.netbsd.org/timerfd_gettime.2 |
| 74 |
#[inline] |
| 75 |
pub fn timerfd_gettime<Fd: AsFd>(fd: Fd) -> io::Result<Itimerspec> { |
| 76 |
backend::time::syscalls::timerfd_gettime(fd.as_fd()) |
| 77 |
} |