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 {
86
86
}
87
87
}
88
88
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
+
89
97
pub fn join ( self ) {
90
98
unsafe {
91
99
let _ = hermit_abi:: join ( self . tid ) ;
Original file line number Diff line number Diff line change @@ -205,6 +205,14 @@ impl Thread {
205
205
}
206
206
}
207
207
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
+
208
216
pub fn join ( self ) {
209
217
// Safety: `ThreadInner` is alive at this point
210
218
let inner = unsafe { self . p_inner . as_ref ( ) } ;
Original file line number Diff line number Diff line change @@ -132,6 +132,14 @@ impl Thread {
132
132
usercalls:: wait_timeout ( 0 , dur, || true ) ;
133
133
}
134
134
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
+
135
143
pub fn join ( self ) {
136
144
self . 0 . wait ( ) ;
137
145
}
Original file line number Diff line number Diff line change @@ -296,6 +296,27 @@ impl Thread {
296
296
}
297
297
}
298
298
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
+
299
320
// Note depends on clock_nanosleep (not supported on os's by apple)
300
321
#[ cfg( any(
301
322
target_os = "freebsd" ,
Original file line number Diff line number Diff line change @@ -171,6 +171,14 @@ impl Thread {
171
171
}
172
172
}
173
173
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
+
174
182
pub fn join ( self ) {
175
183
cfg_if:: cfg_if! {
176
184
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};
8
8
use crate :: sys:: handle:: Handle ;
9
9
use crate :: sys:: { c, stack_overflow} ;
10
10
use crate :: sys_common:: FromInner ;
11
- use crate :: time:: Duration ;
11
+ use crate :: time:: { Duration , Instant } ;
12
12
use crate :: { io, ptr} ;
13
13
14
14
pub const DEFAULT_MIN_STACK_SIZE : usize = 2 * 1024 * 1024 ;
@@ -106,6 +106,14 @@ impl Thread {
106
106
}
107
107
}
108
108
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
+
109
117
pub fn handle ( & self ) -> & Handle {
110
118
& self . handle
111
119
}
Original file line number Diff line number Diff line change @@ -128,6 +128,14 @@ impl Thread {
128
128
}
129
129
}
130
130
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
+
131
139
pub fn join ( self ) {
132
140
join_thread ( self . tid ) . unwrap ( ) ;
133
141
}
Original file line number Diff line number Diff line change @@ -985,44 +985,6 @@ pub fn sleep(dur: Duration) {
985
985
/// ```
986
986
#[ unstable( feature = "thread_sleep_until" , issue = "113752" ) ]
987
987
pub 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 ) {
1026
988
imp:: Thread :: sleep_until ( deadline)
1027
989
}
1028
990
You can’t perform that action at this time.
0 commit comments