1b8a62b91Sopenharmony_ciuse crate::fd::{AsFd, OwnedFd}; 2b8a62b91Sopenharmony_ciuse crate::{backend, io}; 3b8a62b91Sopenharmony_ci 4b8a62b91Sopenharmony_cipub use backend::time::types::{Itimerspec, TimerfdClockId, TimerfdFlags, TimerfdTimerFlags}; 5b8a62b91Sopenharmony_ci 6b8a62b91Sopenharmony_ci/// `timerfd_create(clockid, flags)`—Create a timer. 7b8a62b91Sopenharmony_ci/// 8b8a62b91Sopenharmony_ci/// # References 9b8a62b91Sopenharmony_ci/// - [Linux] 10b8a62b91Sopenharmony_ci/// 11b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_create.2.html 12b8a62b91Sopenharmony_ci#[inline] 13b8a62b91Sopenharmony_cipub fn timerfd_create(clockid: TimerfdClockId, flags: TimerfdFlags) -> io::Result<OwnedFd> { 14b8a62b91Sopenharmony_ci backend::time::syscalls::timerfd_create(clockid, flags) 15b8a62b91Sopenharmony_ci} 16b8a62b91Sopenharmony_ci 17b8a62b91Sopenharmony_ci/// `timerfd_settime(clockid, flags, new_value)`—Set the time on a timer. 18b8a62b91Sopenharmony_ci/// 19b8a62b91Sopenharmony_ci/// # References 20b8a62b91Sopenharmony_ci/// - [Linux] 21b8a62b91Sopenharmony_ci/// 22b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_settime.2.html 23b8a62b91Sopenharmony_ci#[inline] 24b8a62b91Sopenharmony_cipub fn timerfd_settime<Fd: AsFd>( 25b8a62b91Sopenharmony_ci fd: Fd, 26b8a62b91Sopenharmony_ci flags: TimerfdTimerFlags, 27b8a62b91Sopenharmony_ci new_value: &Itimerspec, 28b8a62b91Sopenharmony_ci) -> io::Result<Itimerspec> { 29b8a62b91Sopenharmony_ci backend::time::syscalls::timerfd_settime(fd.as_fd(), flags, new_value) 30b8a62b91Sopenharmony_ci} 31b8a62b91Sopenharmony_ci 32b8a62b91Sopenharmony_ci/// `timerfd_gettime(clockid, flags)`—Query a timer. 33b8a62b91Sopenharmony_ci/// 34b8a62b91Sopenharmony_ci/// # References 35b8a62b91Sopenharmony_ci/// - [Linux] 36b8a62b91Sopenharmony_ci/// 37b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_gettime.2.html 38b8a62b91Sopenharmony_ci#[inline] 39b8a62b91Sopenharmony_cipub fn timerfd_gettime<Fd: AsFd>(fd: Fd) -> io::Result<Itimerspec> { 40b8a62b91Sopenharmony_ci backend::time::syscalls::timerfd_gettime(fd.as_fd()) 41b8a62b91Sopenharmony_ci} 42