File tree Expand file tree Collapse file tree 6 files changed +396
-42
lines changed Expand file tree Collapse file tree 6 files changed +396
-42
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ use sync::Arc;
1616use marker:: { Sync , Send } ;
1717use mem;
1818use clone:: Clone ;
19+ use time:: Instant ;
1920
2021struct Inner {
2122 thread : Thread ,
@@ -74,7 +75,6 @@ impl SignalToken {
7475 pub unsafe fn cast_from_usize ( signal_ptr : usize ) -> SignalToken {
7576 SignalToken { inner : mem:: transmute ( signal_ptr) }
7677 }
77-
7878}
7979
8080impl WaitToken {
@@ -83,4 +83,16 @@ impl WaitToken {
8383 thread:: park ( )
8484 }
8585 }
86+
87+ /// Returns true if we wake up normally, false otherwise.
88+ pub fn wait_max_until ( self , end : Instant ) -> bool {
89+ while !self . inner . woken . load ( Ordering :: SeqCst ) {
90+ let now = Instant :: now ( ) ;
91+ if now >= end {
92+ return false ;
93+ }
94+ thread:: park_timeout ( end - now)
95+ }
96+ true
97+ }
8698}
You can’t perform that action at this time.
0 commit comments