diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-05-21 15:59:27 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-21 15:59:27 +0000 |
commit | dfc689a59521a410585efcd57536f2b7892a84f9 (patch) | |
tree | d96cb41ea06ae4e7f1bf170ccc62cf1b4dd4a21f /src/sys | |
parent | 622e53e787d5f7e476bee0a042220a66a1bf2f31 (diff) | |
parent | a4dd9cd1165a1e5cf864c06f634b426d9c88ebc9 (diff) | |
download | nix-dfc689a59521a410585efcd57536f2b7892a84f9.zip |
Merge #2040
2040: timerfd: Add TFD_TIMER_CANCEL_ON_SET flag r=asomers a=apohrebniak
Hi.
This PR adds an TFD_TIMER_CANCEL_ON_SET flag to use with `timerfd` on Linux and Android
Co-authored-by: Andrii Pohrebniak <andrii.pohrebniak@gmail.com>
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/time.rs | 1 | ||||
-rw-r--r-- | src/sys/timerfd.rs | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/sys/time.rs b/src/sys/time.rs index a1894e4d..30ee5fd1 100644 --- a/src/sys/time.rs +++ b/src/sys/time.rs @@ -93,6 +93,7 @@ pub(crate) mod timer { /// Flags that are used for arming the timer. pub struct TimerSetTimeFlags: libc::c_int { const TFD_TIMER_ABSTIME = libc::TFD_TIMER_ABSTIME; + const TFD_TIMER_CANCEL_ON_SET = libc::TFD_TIMER_CANCEL_ON_SET; } } #[cfg(any( diff --git a/src/sys/timerfd.rs b/src/sys/timerfd.rs index 90a05a8c..c4337c9d 100644 --- a/src/sys/timerfd.rs +++ b/src/sys/timerfd.rs @@ -135,6 +135,13 @@ impl TimerFd { /// Then the one shot TimeSpec and the delay TimeSpec of the delayed /// interval are going to be interpreted as absolute. /// + /// # Cancel on a clock change + /// + /// If you set a `TFD_TIMER_CANCEL_ON_SET` alongside `TFD_TIMER_ABSTIME` + /// and the clock for this timer is `CLOCK_REALTIME` or `CLOCK_REALTIME_ALARM`, + /// then this timer is marked as cancelable if the real-time clock undergoes + /// a discontinuous change. + /// /// # Disabling alarms /// /// Note: Only one alarm can be set for any given timer. Setting a new alarm @@ -202,6 +209,9 @@ impl TimerFd { /// Note: If the alarm is unset, then you will wait forever. pub fn wait(&self) -> Result<()> { while let Err(e) = read(self.fd.as_fd().as_raw_fd(), &mut [0u8; 8]) { + if e == Errno::ECANCELED { + break; + } if e != Errno::EINTR { return Err(e); } |