File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
library/std/src/sys/pal/unix Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -310,11 +310,17 @@ impl Thread {
310310 target_os = "vxworks" ,
311311 ) ) ]
312312 pub fn sleep_until ( deadline : Instant ) {
313- let mut ts = deadline
314- . into_inner ( )
315- . into_timespec ( )
316- . to_timespec ( )
317- . expect ( "Timespec is narrower then libc::timespec thus conversion can't fail" ) ;
313+ let Some ( mut ts) = deadline. into_inner ( ) . into_timespec ( ) . to_timespec ( ) else {
314+ // The deadline is further in the future then can be passed to
315+ // clock_nanosleep. We have to use Self::sleep intead. This might
316+ // happen on 32 bit platforms, especially closer to 2038.
317+ let now = Instant :: now ( ) ;
318+ if let Some ( delay) = deadline. checked_duration_since ( now) {
319+ Self :: sleep ( delay) ;
320+ }
321+ return ;
322+ } ;
323+
318324 let ts_ptr = & mut ts as * mut _ ;
319325
320326 // If we're awoken with a signal and the return value is -1
@@ -347,7 +353,6 @@ impl Thread {
347353 ) ) ) ]
348354 pub fn sleep_until ( deadline : Instant ) {
349355 let now = Instant :: now ( ) ;
350-
351356 if let Some ( delay) = deadline. checked_duration_since ( now) {
352357 Self :: sleep ( delay) ;
353358 }
You can’t perform that action at this time.
0 commit comments