mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
openbsd: convert futex timeout managment to Timespec usage
This commit is contained in:
parent
532be942dd
commit
f75d02d669
@ -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(
|
||||
|
@ -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 }
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user