File tree Expand file tree Collapse file tree 5 files changed +20
-5
lines changed Expand file tree Collapse file tree 5 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use super::hermit_abi;
44use crate :: ffi:: CStr ;
55use crate :: mem:: ManuallyDrop ;
66use crate :: num:: NonZero ;
7- use crate :: time:: Duration ;
7+ use crate :: time:: { Duration , Instant } ;
88use crate :: { io, ptr} ;
99
1010pub type Tid = hermit_abi:: Tid ;
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ use super::unsupported;
55use crate :: ffi:: CStr ;
66use crate :: io;
77use crate :: num:: NonZero ;
8- use crate :: time:: Duration ;
8+ use crate :: time:: { Duration , Instant } ;
99
1010pub struct Thread ( task_queue:: JoinHandle ) ;
1111
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ use crate::ffi::CStr;
22use crate :: mem:: { self , ManuallyDrop } ;
33use crate :: num:: NonZero ;
44use crate :: sys:: os;
5- use crate :: time:: Duration ;
5+ use crate :: time:: { Duration , Instant } ;
66use crate :: { cmp, io, ptr} ;
77
88pub const DEFAULT_MIN_STACK_SIZE : usize = 8 * 1024 ;
@@ -109,6 +109,14 @@ impl Thread {
109109 }
110110 }
111111
112+ pub fn sleep_until ( deadline : Instant ) {
113+ let now = Instant :: now ( ) ;
114+
115+ if let Some ( delay) = deadline. checked_duration_since ( now) {
116+ Self :: sleep ( delay) ;
117+ }
118+ }
119+
112120 /// must join, because no pthread_detach supported
113121 pub fn join ( self ) {
114122 let id = self . into_id ( ) ;
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ use crate::ffi::CStr;
33use crate :: io;
44use crate :: num:: NonZero ;
55use crate :: ptr:: NonNull ;
6- use crate :: time:: Duration ;
6+ use crate :: time:: { Duration , Instant } ;
77
88pub struct Thread ( !) ;
99
@@ -39,6 +39,14 @@ impl Thread {
3939 }
4040 }
4141
42+ pub fn sleep_until ( deadline : Instant ) {
43+ let now = Instant :: now ( ) ;
44+
45+ if let Some ( delay) = deadline. checked_duration_since ( now) {
46+ sleep ( delay) ;
47+ }
48+ }
49+
4250 pub fn join ( self ) {
4351 self . 0
4452 }
Original file line number Diff line number Diff line change @@ -297,7 +297,6 @@ impl Thread {
297297 }
298298
299299 #[ cfg( not( any(
300- target_vendor = "apple" ,
301300 target_os = "freebsd" ,
302301 target_os = "netbsd" ,
303302 target_os = "linux" ,
You can’t perform that action at this time.
0 commit comments