diff options
| author | Sébastien Marie <semarie@online.fr> | 2022-05-11 04:50:23 +0000 |
|---|---|---|
| committer | Sébastien Marie <semarie@online.fr> | 2022-05-11 04:50:23 +0000 |
| commit | f75d02d66975bed3636e89f56077bbc53fe5f74d (patch) | |
| tree | 38d489997a6ee2c7bc3e728d3f62158d51edd34f /library/std/src | |
| parent | 532be942ddf8f40d086e54d157453434b16e9647 (diff) | |
| download | rust-f75d02d66975bed3636e89f56077bbc53fe5f74d.tar.gz rust-f75d02d66975bed3636e89f56077bbc53fe5f74d.zip | |
openbsd: convert futex timeout managment to Timespec usage
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/sys/unix/futex.rs | 14 | ||||
| -rw-r--r-- | library/std/src/sys/unix/time.rs | 2 |
2 files changed, 7 insertions, 9 deletions
diff --git a/library/std/src/sys/unix/futex.rs b/library/std/src/sys/unix/futex.rs index 8d5ad18997d..d70108e7bd6 100644 --- a/library/std/src/sys/unix/futex.rs +++ b/library/std/src/sys/unix/futex.rs @@ -136,15 +136,13 @@ pub fn futex_wake_all(futex: &AtomicU32) { #[cfg(target_os = "openbsd")] pub fn futex_wait(futex: &AtomicU32, expected: u32, timeout: Option<Duration>) -> bool { + use super::time::Timespec; use crate::ptr::{null, null_mut}; - let timespec = timeout.and_then(|d| { - Some(libc::timespec { - // Sleep forever if the timeout is longer than fits in a timespec. - tv_sec: d.as_secs().try_into().ok()?, - // This conversion never truncates, as subsec_nanos is always <1e9. - tv_nsec: d.subsec_nanos() as _, - }) - }); + + // Overflows are rounded up to an infinite timeout (None). + let timespec = timeout + .and_then(|d| Timespec::zero().checked_add_duration(&d)) + .and_then(|t| t.to_timespec()); let r = unsafe { libc::futex( diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs index 333182bdad4..df95f1494fd 100644 --- a/library/std/src/sys/unix/time.rs +++ b/library/std/src/sys/unix/time.rs @@ -51,7 +51,7 @@ impl fmt::Debug for SystemTime { } impl Timespec { - const fn zero() -> Timespec { + pub const fn zero() -> Timespec { Timespec { tv_sec: 0, tv_nsec: 0 } } |
