Skip to content

Commit 291e460

Browse files
committed
Revert "Revert "add more default sleep_until to different pals""
This reverts commit 4c0b944.
1 parent bb961b9 commit 291e460

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

library/std/src/sys/pal/hermit/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::hermit_abi;
44
use crate::ffi::CStr;
55
use crate::mem::ManuallyDrop;
66
use crate::num::NonZero;
7-
use crate::time::Duration;
7+
use crate::time::{Duration, Instant};
88
use crate::{io, ptr};
99

1010
pub type Tid = hermit_abi::Tid;

library/std/src/sys/pal/sgx/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::unsupported;
55
use crate::ffi::CStr;
66
use crate::io;
77
use crate::num::NonZero;
8-
use crate::time::Duration;
8+
use crate::time::{Duration, Instant};
99

1010
pub struct Thread(task_queue::JoinHandle);
1111

library/std/src/sys/pal/teeos/thread.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::ffi::CStr;
22
use crate::mem::{self, ManuallyDrop};
33
use crate::num::NonZero;
44
use crate::sys::os;
5-
use crate::time::Duration;
5+
use crate::time::{Duration, Instant};
66
use crate::{cmp, io, ptr};
77

88
pub const DEFAULT_MIN_STACK_SIZE: usize = 8 * 1024;
@@ -109,6 +109,14 @@ impl Thread {
109109
}
110110
}
111111

112+
pub fn sleep_until(deadline: Instant) {
113+
let now = Instant::now();
114+
115+
if let Some(delay) = deadline.checked_duration_since(now) {
116+
Self::sleep(delay);
117+
}
118+
}
119+
112120
/// must join, because no pthread_detach supported
113121
pub fn join(self) {
114122
let id = self.into_id();

library/std/src/sys/pal/uefi/thread.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::ffi::CStr;
33
use crate::io;
44
use crate::num::NonZero;
55
use crate::ptr::NonNull;
6-
use crate::time::Duration;
6+
use crate::time::{Duration, Instant};
77

88
pub struct Thread(!);
99

@@ -39,6 +39,14 @@ impl Thread {
3939
}
4040
}
4141

42+
pub fn sleep_until(deadline: Instant) {
43+
let now = Instant::now();
44+
45+
if let Some(delay) = deadline.checked_duration_since(now) {
46+
sleep(delay);
47+
}
48+
}
49+
4250
pub fn join(self) {
4351
self.0
4452
}

library/std/src/sys/pal/unix/thread.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ impl Thread {
297297
}
298298

299299
#[cfg(not(any(
300-
target_vendor = "apple",
301300
target_os = "freebsd",
302301
target_os = "netbsd",
303302
target_os = "linux",

0 commit comments

Comments
 (0)