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 {
9090 let now = Instant :: now ( ) ;
9191
9292 if let Some ( delay) = deadline. checked_duration_since ( now) {
93- sleep ( delay) ;
93+ Self :: sleep ( delay) ;
9494 }
9595 }
9696
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ use crate::mem::ManuallyDrop;
1010use crate :: num:: NonZero ;
1111use crate :: ptr:: NonNull ;
1212use crate :: sync:: atomic:: { Atomic , AtomicUsize , Ordering } ;
13- use crate :: time:: Duration ;
13+ use crate :: time:: { Duration , Instant } ;
1414use crate :: { hint, io} ;
1515
1616pub struct Thread {
@@ -209,7 +209,7 @@ impl Thread {
209209 let now = Instant :: now ( ) ;
210210
211211 if let Some ( delay) = deadline. checked_duration_since ( now) {
212- sleep ( delay) ;
212+ Self :: sleep ( delay) ;
213213 }
214214 }
215215
Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ impl Thread {
136136 let now = Instant :: now ( ) ;
137137
138138 if let Some ( delay) = deadline. checked_duration_since ( now) {
139- sleep ( delay) ;
139+ Self :: sleep ( delay) ;
140140 }
141141 }
142142
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ impl Thread {
4343 let now = Instant :: now ( ) ;
4444
4545 if let Some ( delay) = deadline. checked_duration_since ( now) {
46- sleep ( delay) ;
46+ Self :: sleep ( delay) ;
4747 }
4848 }
4949
Original file line number Diff line number Diff line change @@ -296,27 +296,7 @@ impl Thread {
296296 }
297297 }
298298
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
320300 #[ cfg( any(
321301 target_os = "freebsd" ,
322302 target_os = "netbsd" ,
@@ -352,6 +332,27 @@ impl Thread {
352332 }
353333 }
354334
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+
355356 pub fn join ( self ) {
356357 let id = self . into_id ( ) ;
357358 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 {
2626 panic ! ( "can't sleep" ) ;
2727 }
2828
29+ pub fn sleep_until ( _deadline : Instant ) {
30+ panic ! ( "can't sleep)" ;
31+ }
32+
2933 pub fn join ( self ) {
3034 self . 0
3135 }
Original file line number Diff line number Diff line change 22
33use crate :: ffi:: CStr ;
44use crate :: num:: NonZero ;
5- use crate :: time:: Duration ;
5+ use crate :: time:: { Duration , Instant } ;
66use crate :: { io, mem} ;
77
88cfg_if:: cfg_if! {
@@ -175,7 +175,7 @@ impl Thread {
175175 let now = Instant :: now ( ) ;
176176
177177 if let Some ( delay) = deadline. checked_duration_since ( now) {
178- sleep ( delay) ;
178+ Self :: sleep ( delay) ;
179179 }
180180 }
181181
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ use crate::ffi::CStr;
22use crate :: io;
33use crate :: num:: NonZero ;
44use crate :: sys:: unsupported;
5- use crate :: time:: Duration ;
5+ use crate :: time:: { Duration , Instant } ;
66
77pub struct Thread ( !) ;
88
@@ -41,6 +41,14 @@ impl Thread {
4141 }
4242 }
4343
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+
4452 pub fn join ( self ) { }
4553}
4654
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ use crate::os::xous::ffi::{
88 map_memory, update_memory_flags,
99} ;
1010use crate :: os:: xous:: services:: { TicktimerScalar , ticktimer_server} ;
11- use crate :: time:: Duration ;
11+ use crate :: time:: { Duration , Instant } ;
1212
1313pub struct Thread {
1414 tid : ThreadId ,
@@ -132,7 +132,7 @@ impl Thread {
132132 let now = Instant :: now ( ) ;
133133
134134 if let Some ( delay) = deadline. checked_duration_since ( now) {
135- sleep ( delay) ;
135+ Self :: sleep ( delay) ;
136136 }
137137 }
138138
You can’t perform that action at this time.
0 commit comments