File tree Expand file tree Collapse file tree 2 files changed +7
-9
lines changed Expand file tree Collapse file tree 2 files changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -136,15 +136,13 @@ pub fn futex_wake_all(futex: &AtomicU32) {
136
136
137
137
#[ cfg( target_os = "openbsd" ) ]
138
138
pub fn futex_wait ( futex : & AtomicU32 , expected : u32 , timeout : Option < Duration > ) -> bool {
139
+ use super :: time:: Timespec ;
139
140
use crate :: ptr:: { null, null_mut} ;
140
- let timespec = timeout. and_then ( |d| {
141
- Some ( libc:: timespec {
142
- // Sleep forever if the timeout is longer than fits in a timespec.
143
- tv_sec : d. as_secs ( ) . try_into ( ) . ok ( ) ?,
144
- // This conversion never truncates, as subsec_nanos is always <1e9.
145
- tv_nsec : d. subsec_nanos ( ) as _ ,
146
- } )
147
- } ) ;
141
+
142
+ // Overflows are rounded up to an infinite timeout (None).
143
+ let timespec = timeout
144
+ . and_then ( |d| Timespec :: zero ( ) . checked_add_duration ( & d) )
145
+ . and_then ( |t| t. to_timespec ( ) ) ;
148
146
149
147
let r = unsafe {
150
148
libc:: futex (
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ impl fmt::Debug for SystemTime {
51
51
}
52
52
53
53
impl Timespec {
54
- const fn zero ( ) -> Timespec {
54
+ pub const fn zero ( ) -> Timespec {
55
55
Timespec { tv_sec : 0 , tv_nsec : 0 }
56
56
}
57
57
You can’t perform that action at this time.
0 commit comments