@@ -364,21 +364,22 @@ impl Inner {
364
364
// Block the current thread on the conditional variable.
365
365
m = match deadline {
366
366
None => self . cvar . wait ( m) . unwrap ( ) ,
367
- Some ( deadline) => match deadline. checked_duration_since ( Instant :: now ( ) ) {
368
- // We could check for a timeout here, in the return value of wait_timeout,
369
- // but in the case that a timeout and an unpark arrive simultaneously, we
370
- // prefer to report the former.
371
- Some ( duration) if duration > Duration :: from_secs ( 0 ) => {
372
- self . cvar . wait_timeout ( m, duration) . unwrap ( ) . 0
367
+ Some ( deadline) => {
368
+ let now = Instant :: now ( ) ;
369
+ if now < deadline {
370
+ // We could check for a timeout here, in the return value of wait_timeout,
371
+ // but in the case that a timeout and an unpark arrive simultaneously, we
372
+ // prefer to report the former.
373
+ self . cvar . wait_timeout ( m, deadline - now) . unwrap ( ) . 0
374
+ } else {
375
+ // We've timed out; swap out the state back to empty on our way out
376
+ return match self . state . swap ( EMPTY , SeqCst ) {
377
+ NOTIFIED => UnparkReason :: Unparked , // got a notification
378
+ PARKED => UnparkReason :: Timeout , // no notification
379
+ n => panic ! ( "inconsistent park_timeout state: {}" , n) ,
380
+ } ;
373
381
}
374
-
375
- // We've timed out; swap out the state back to empty on our way out
376
- _ => match self . state . swap ( EMPTY , SeqCst ) {
377
- NOTIFIED => return UnparkReason :: Unparked , // got a notification
378
- PARKED => return UnparkReason :: Timeout , // no notification
379
- n => panic ! ( "inconsistent park_timeout state: {}" , n) ,
380
- } ,
381
- } ,
382
+ }
382
383
} ;
383
384
384
385
if self
0 commit comments