Coverage Report

Created: 2025-07-11 06:22

/rust/registry/src/index.crates.io-6f17d22bba15001f/rustix-1.0.7/src/time/timerfd.rs
Line
Count
Source (jump to first uncovered line)
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
///
29
/// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_create.2.html
30
#[inline]
31
0
pub fn timerfd_create(clockid: TimerfdClockId, flags: TimerfdFlags) -> io::Result<OwnedFd> {
32
0
    backend::time::syscalls::timerfd_create(clockid, flags)
33
0
}
34
35
/// `timerfd_settime(clockid, flags, new_value)`—Set the time on a timer.
36
///
37
/// # References
38
///  - [Linux]
39
///
40
/// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_settime.2.html
41
#[inline]
42
0
pub fn timerfd_settime<Fd: AsFd>(
43
0
    fd: Fd,
44
0
    flags: TimerfdTimerFlags,
45
0
    new_value: &Itimerspec,
46
0
) -> io::Result<Itimerspec> {
47
0
    backend::time::syscalls::timerfd_settime(fd.as_fd(), flags, new_value)
48
0
}
49
50
/// `timerfd_gettime(clockid, flags)`—Query a timer.
51
///
52
/// # References
53
///  - [Linux]
54
///
55
/// [Linux]: https://man7.org/linux/man-pages/man2/timerfd_gettime.2.html
56
#[inline]
57
0
pub fn timerfd_gettime<Fd: AsFd>(fd: Fd) -> io::Result<Itimerspec> {
58
0
    backend::time::syscalls::timerfd_gettime(fd.as_fd())
59
0
}