File tree Expand file tree Collapse file tree 9 files changed +44
-31
lines changed Expand file tree Collapse file tree 9 files changed +44
-31
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ impl Thread {
90
90
let now = Instant :: now ( ) ;
91
91
92
92
if let Some ( delay) = deadline. checked_duration_since ( now) {
93
- sleep ( delay) ;
93
+ Self :: sleep ( delay) ;
94
94
}
95
95
}
96
96
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ use crate::mem::ManuallyDrop;
10
10
use crate :: num:: NonZero ;
11
11
use crate :: ptr:: NonNull ;
12
12
use crate :: sync:: atomic:: { Atomic , AtomicUsize , Ordering } ;
13
- use crate :: time:: Duration ;
13
+ use crate :: time:: { Duration , Instant } ;
14
14
use crate :: { hint, io} ;
15
15
16
16
pub struct Thread {
@@ -209,7 +209,7 @@ impl Thread {
209
209
let now = Instant :: now ( ) ;
210
210
211
211
if let Some ( delay) = deadline. checked_duration_since ( now) {
212
- sleep ( delay) ;
212
+ Self :: sleep ( delay) ;
213
213
}
214
214
}
215
215
Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ impl Thread {
136
136
let now = Instant :: now ( ) ;
137
137
138
138
if let Some ( delay) = deadline. checked_duration_since ( now) {
139
- sleep ( delay) ;
139
+ Self :: sleep ( delay) ;
140
140
}
141
141
}
142
142
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ impl Thread {
43
43
let now = Instant :: now ( ) ;
44
44
45
45
if let Some ( delay) = deadline. checked_duration_since ( now) {
46
- sleep ( delay) ;
46
+ Self :: sleep ( delay) ;
47
47
}
48
48
}
49
49
Original file line number Diff line number Diff line change @@ -296,27 +296,7 @@ impl Thread {
296
296
}
297
297
}
298
298
299
- #[ cfg( not( any(
300
- target_os = "freebsd" ,
301
- target_os = "netbsd" ,
302
- target_os = "linux" ,
303
- target_os = "android" ,
304
- target_os = "solaris" ,
305
- target_os = "illumos" ,
306
- target_os = "dragonfly" ,
307
- target_os = "hurd" ,
308
- target_os = "fuchsia" ,
309
- target_os = "vxworks" ,
310
- ) ) ) ]
311
- pub fn sleep_until ( deadline : Instant ) {
312
- let now = Instant :: now ( ) ;
313
-
314
- if let Some ( delay) = deadline. checked_duration_since ( now) {
315
- sleep ( delay) ;
316
- }
317
- }
318
-
319
- // Note depends on clock_nanosleep (not supported on os's by apple)
299
+ // Any unix that has clock_nanosleep
320
300
#[ cfg( any(
321
301
target_os = "freebsd" ,
322
302
target_os = "netbsd" ,
@@ -352,6 +332,27 @@ impl Thread {
352
332
}
353
333
}
354
334
335
+ // Any unix that does not have clock_nanosleep
336
+ #[ cfg( not( any(
337
+ target_os = "freebsd" ,
338
+ target_os = "netbsd" ,
339
+ target_os = "linux" ,
340
+ target_os = "android" ,
341
+ target_os = "solaris" ,
342
+ target_os = "illumos" ,
343
+ target_os = "dragonfly" ,
344
+ target_os = "hurd" ,
345
+ target_os = "fuchsia" ,
346
+ target_os = "vxworks" ,
347
+ ) ) ) ]
348
+ pub fn sleep_until ( deadline : Instant ) {
349
+ let now = Instant :: now ( ) ;
350
+
351
+ if let Some ( delay) = deadline. checked_duration_since ( now) {
352
+ sleep ( delay) ;
353
+ }
354
+ }
355
+
355
356
pub fn join ( self ) {
356
357
let id = self . into_id ( ) ;
357
358
let ret = unsafe { libc:: pthread_join ( id, ptr:: null_mut ( ) ) } ;
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ impl Thread {
26
26
panic ! ( "can't sleep" ) ;
27
27
}
28
28
29
+ pub fn sleep_until ( _deadline : Instant ) {
30
+ panic ! ( "can't sleep" ) ;
31
+ }
32
+
29
33
pub fn join ( self ) {
30
34
self . 0
31
35
}
Original file line number Diff line number Diff line change 2
2
3
3
use crate :: ffi:: CStr ;
4
4
use crate :: num:: NonZero ;
5
- use crate :: time:: Duration ;
5
+ use crate :: time:: { Duration , Instant } ;
6
6
use crate :: { io, mem} ;
7
7
8
8
cfg_if:: cfg_if! {
@@ -175,7 +175,7 @@ impl Thread {
175
175
let now = Instant :: now ( ) ;
176
176
177
177
if let Some ( delay) = deadline. checked_duration_since ( now) {
178
- sleep ( delay) ;
178
+ Self :: sleep ( delay) ;
179
179
}
180
180
}
181
181
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ use crate::ffi::CStr;
2
2
use crate :: io;
3
3
use crate :: num:: NonZero ;
4
4
use crate :: sys:: unsupported;
5
- use crate :: time:: Duration ;
5
+ use crate :: time:: { Duration , Instant } ;
6
6
7
7
pub struct Thread ( !) ;
8
8
@@ -41,6 +41,14 @@ impl Thread {
41
41
}
42
42
}
43
43
44
+ pub fn sleep_until ( deadline : Instant ) {
45
+ let now = Instant :: now ( ) ;
46
+
47
+ if let Some ( delay) = deadline. checked_duration_since ( now) {
48
+ Self :: sleep ( delay) ;
49
+ }
50
+ }
51
+
44
52
pub fn join ( self ) { }
45
53
}
46
54
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ use crate::os::xous::ffi::{
8
8
map_memory, update_memory_flags,
9
9
} ;
10
10
use crate :: os:: xous:: services:: { TicktimerScalar , ticktimer_server} ;
11
- use crate :: time:: Duration ;
11
+ use crate :: time:: { Duration , Instant } ;
12
12
13
13
pub struct Thread {
14
14
tid : ThreadId ,
@@ -132,7 +132,7 @@ impl Thread {
132
132
let now = Instant :: now ( ) ;
133
133
134
134
if let Some ( delay) = deadline. checked_duration_since ( now) {
135
- sleep ( delay) ;
135
+ Self :: sleep ( delay) ;
136
136
}
137
137
}
138
138
You can’t perform that action at this time.
0 commit comments