File tree Expand file tree Collapse file tree 8 files changed +70
-39
lines changed Expand file tree Collapse file tree 8 files changed +70
-39
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,14 @@ impl Thread {
8686 }
8787 }
8888
89+ pub fn sleep_until ( deadline : Instant ) {
90+ let now = Instant :: now ( ) ;
91+
92+ if let Some ( delay) = deadline. checked_duration_since ( now) {
93+ sleep ( delay) ;
94+ }
95+ }
96+
8997 pub fn join ( self ) {
9098 unsafe {
9199 let _ = hermit_abi:: join ( self . tid ) ;
Original file line number Diff line number Diff line change @@ -205,6 +205,14 @@ impl Thread {
205205 }
206206 }
207207
208+ pub fn sleep_until ( deadline : Instant ) {
209+ let now = Instant :: now ( ) ;
210+
211+ if let Some ( delay) = deadline. checked_duration_since ( now) {
212+ sleep ( delay) ;
213+ }
214+ }
215+
208216 pub fn join ( self ) {
209217 // Safety: `ThreadInner` is alive at this point
210218 let inner = unsafe { self . p_inner . as_ref ( ) } ;
Original file line number Diff line number Diff line change @@ -132,6 +132,14 @@ impl Thread {
132132 usercalls:: wait_timeout ( 0 , dur, || true ) ;
133133 }
134134
135+ pub fn sleep_until ( deadline : Instant ) {
136+ let now = Instant :: now ( ) ;
137+
138+ if let Some ( delay) = deadline. checked_duration_since ( now) {
139+ sleep ( delay) ;
140+ }
141+ }
142+
135143 pub fn join ( self ) {
136144 self . 0 . wait ( ) ;
137145 }
Original file line number Diff line number Diff line change @@ -296,6 +296,27 @@ impl Thread {
296296 }
297297 }
298298
299+ #[ cfg( not( any(
300+ target_vendor = "apple" ,
301+ target_os = "freebsd" ,
302+ target_os = "netbsd" ,
303+ target_os = "linux" ,
304+ target_os = "android" ,
305+ target_os = "solaris" ,
306+ target_os = "illumos" ,
307+ target_os = "dragonfly" ,
308+ target_os = "hurd" ,
309+ target_os = "fuchsia" ,
310+ target_os = "vxworks" ,
311+ ) ) ) ]
312+ pub fn sleep_until ( deadline : Instant ) {
313+ let now = Instant :: now ( ) ;
314+
315+ if let Some ( delay) = deadline. checked_duration_since ( now) {
316+ sleep ( delay) ;
317+ }
318+ }
319+
299320 // Note depends on clock_nanosleep (not supported on os's by apple)
300321 #[ cfg( any(
301322 target_os = "freebsd" ,
Original file line number Diff line number Diff line change @@ -171,6 +171,14 @@ impl Thread {
171171 }
172172 }
173173
174+ pub fn sleep_until ( deadline : Instant ) {
175+ let now = Instant :: now ( ) ;
176+
177+ if let Some ( delay) = deadline. checked_duration_since ( now) {
178+ sleep ( delay) ;
179+ }
180+ }
181+
174182 pub fn join ( self ) {
175183 cfg_if:: cfg_if! {
176184 if #[ cfg( target_feature = "atomics" ) ] {
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ use crate::os::windows::io::{AsRawHandle, HandleOrNull};
88use crate :: sys:: handle:: Handle ;
99use crate :: sys:: { c, stack_overflow} ;
1010use crate :: sys_common:: FromInner ;
11- use crate :: time:: Duration ;
11+ use crate :: time:: { Duration , Instant } ;
1212use crate :: { io, ptr} ;
1313
1414pub const DEFAULT_MIN_STACK_SIZE : usize = 2 * 1024 * 1024 ;
@@ -106,6 +106,14 @@ impl Thread {
106106 }
107107 }
108108
109+ pub fn sleep_until ( deadline : Instant ) {
110+ let now = Instant :: now ( ) ;
111+
112+ if let Some ( delay) = deadline. checked_duration_since ( now) {
113+ Self :: sleep ( delay) ;
114+ }
115+ }
116+
109117 pub fn handle ( & self ) -> & Handle {
110118 & self . handle
111119 }
Original file line number Diff line number Diff line change @@ -128,6 +128,14 @@ impl Thread {
128128 }
129129 }
130130
131+ pub fn sleep_until ( deadline : Instant ) {
132+ let now = Instant :: now ( ) ;
133+
134+ if let Some ( delay) = deadline. checked_duration_since ( now) {
135+ sleep ( delay) ;
136+ }
137+ }
138+
131139 pub fn join ( self ) {
132140 join_thread ( self . tid ) . unwrap ( ) ;
133141 }
Original file line number Diff line number Diff line change @@ -985,44 +985,6 @@ pub fn sleep(dur: Duration) {
985985/// ```
986986#[ unstable( feature = "thread_sleep_until" , issue = "113752" ) ]
987987pub fn sleep_until ( deadline : Instant ) {
988- impl_sleep_until ( deadline)
989- }
990-
991- #[ cfg( not( any(
992- target_os = "freebsd" ,
993- target_os = "netbsd" ,
994- target_os = "linux" ,
995- target_os = "android" ,
996- target_os = "solaris" ,
997- target_os = "illumos" ,
998- target_os = "dragonfly" ,
999- target_os = "hurd" ,
1000- target_os = "fuchsia" ,
1001- target_os = "vxworks" ,
1002- ) ) ) ]
1003- #[ inline]
1004- fn impl_sleep_until ( deadline : Instant ) {
1005- let now = Instant :: now ( ) ;
1006-
1007- if let Some ( delay) = deadline. checked_duration_since ( now) {
1008- sleep ( delay) ;
1009- }
1010- }
1011-
1012- #[ cfg( any(
1013- target_os = "freebsd" ,
1014- target_os = "netbsd" ,
1015- target_os = "linux" ,
1016- target_os = "android" ,
1017- target_os = "solaris" ,
1018- target_os = "illumos" ,
1019- target_os = "dragonfly" ,
1020- target_os = "hurd" ,
1021- target_os = "fuchsia" ,
1022- target_os = "vxworks" ,
1023- ) ) ]
1024- #[ inline]
1025- fn impl_sleep_until ( deadline : Instant ) {
1026988 imp:: Thread :: sleep_until ( deadline)
1027989}
1028990
You can’t perform that action at this time.
0 commit comments