This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -185,16 +185,15 @@ pub fn futex_wake_all(futex: &AtomicU32) {
185185#[ cfg( target_os = "dragonfly" ) ]
186186pub fn futex_wait ( futex : & AtomicU32 , expected : u32 , timeout : Option < Duration > ) -> bool {
187187 use crate :: convert:: TryFrom ;
188+
189+ // A timeout of 0 means infinite.
190+ // We round smaller timeouts up to 1 millisecond.
191+ // Overflows are rounded up to an infinite timeout.
192+ let timeout_ms =
193+ timeout. and_then ( |d| Some ( i32:: try_from ( d. as_millis ( ) ) . ok ( ) ?. max ( 1 ) ) ) . unwrap_or ( 0 ) ;
194+
188195 let r = unsafe {
189- libc:: umtx_sleep (
190- futex as * const AtomicU32 as * const i32 ,
191- expected as i32 ,
192- // A timeout of 0 means infinite, so we round smaller timeouts up to 1 millisecond.
193- // Timeouts larger than i32::MAX milliseconds saturate.
194- timeout. map_or ( 0 , |d| {
195- i32:: try_from ( d. as_millis ( ) ) . map_or ( i32:: MAX , |millis| millis. max ( 1 ) )
196- } ) ,
197- )
196+ libc:: umtx_sleep ( futex as * const AtomicU32 as * const i32 , expected as i32 , timeout_ms)
198197 } ;
199198
200199 r == 0 || super :: os:: errno ( ) != libc:: ETIMEDOUT
You can’t perform that action at this time.
0 commit comments