File tree Expand file tree Collapse file tree 3 files changed +6
-4
lines changed
Expand file tree Collapse file tree 3 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0));
1414impl Instant {
1515 pub fn now ( ) -> Instant {
1616 let result = blocking_scalar ( ticktimer_server ( ) , ElapsedNs . into ( ) )
17- . expect ( "failed to request elapsed_ms " ) ;
17+ . expect ( "failed to request elapsed " ) ;
1818 let lower = result[ 0 ] ;
1919 let upper = result[ 1 ] ;
2020 Instant { 0 : Duration :: from_nanos ( lower as u64 | ( upper as u64 ) << 32 ) }
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ impl Condvar {
6262 // Returns false on timeout
6363 pub unsafe fn wait_timeout ( & self , mutex : & Mutex , dur : Duration ) -> bool {
6464 let mut nanos = dur. as_nanos ( ) as u64 ;
65- // Ensure we don't wait for 0 ms, which would cause us to wait forever
65+ // Ensure we don't send zero as parameter, as it could be handled special in the future.
6666 if nanos == 0 {
6767 nanos = 1 ;
6868 }
Original file line number Diff line number Diff line change @@ -30,10 +30,12 @@ impl Parker {
3030 self . mtx . unlock ( ) ;
3131 }
3232
33- pub unsafe fn park_timeout ( self : Pin < & Self > , timeout : Duration ) {
33+ pub unsafe fn park_timeout ( self : Pin < & Self > , mut timeout : Duration ) {
3434 self . mtx . lock ( ) ;
35- while !self . token . load ( Ordering :: SeqCst ) {
35+ while timeout > Duration :: ZERO && !self . token . load ( Ordering :: SeqCst ) {
36+ let start = crate :: time:: Instant :: now ( ) ;
3637 self . condvar . wait_timeout ( & self . mtx , timeout) ;
38+ timeout = timeout. saturating_sub ( start. elapsed ( ) ) ;
3739 }
3840 self . token . store ( false , Ordering :: SeqCst ) ;
3941 self . mtx . unlock ( ) ;
You can’t perform that action at this time.
0 commit comments