Skip to content

Commit d1ae96a

Browse files
dvdskjoboet
andcommitted
(lib/sleep_until) use target_vendor apple + fix windows removeal + add
more unix platforms target_vendor's done by: Co-authored-by: Jonas Böttiger <[email protected]>
1 parent 1f32d20 commit d1ae96a

File tree

3 files changed

+17
-35
lines changed

3 files changed

+17
-35
lines changed

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

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,10 @@ impl Thread {
310310
target_os = "android",
311311
target_os = "solaris",
312312
target_os = "illumos",
313-
target_os = "macos",
314-
target_os = "ios",
315-
target_os = "tvos",
316-
target_os = "watchos"
313+
target_os = "dragonfly",
314+
target_os = "hurd",
315+
target_os = "fuchsia",
316+
target_vendor = "apple"
317317
)))]
318318
pub fn sleep_until(deadline: Instant) {
319319
let now = Instant::now();
@@ -323,14 +323,17 @@ impl Thread {
323323
}
324324
}
325325

326-
// Note depends on clock_nanosleep (not supported on macos/ios/watchos/tvos)
326+
// Note depends on clock_nanosleep (not supported on os's by apple)
327327
#[cfg(any(
328328
target_os = "freebsd",
329329
target_os = "netbsd",
330330
target_os = "linux",
331331
target_os = "android",
332332
target_os = "solaris",
333333
target_os = "illumos",
334+
target_os = "dragonfly",
335+
target_os = "hurd",
336+
target_os = "fuchsia",
334337
))]
335338
pub fn sleep_until(deadline: crate::time::Instant) {
336339
let mut ts = deadline
@@ -355,13 +358,7 @@ impl Thread {
355358
}
356359
}
357360

358-
#[cfg(any(
359-
target_os = "macos",
360-
target_os = "ios",
361-
target_os = "tvos",
362-
target_os = "watchos",
363-
target_os = "visionos"
364-
))]
361+
#[cfg(target_vendor = "apple")]
365362
pub fn sleep_until(deadline: crate::time::Instant) {
366363
use core::mem::MaybeUninit;
367364

@@ -398,35 +395,17 @@ impl Thread {
398395
}
399396
}
400397

401-
#[cfg(any(
402-
target_os = "macos",
403-
target_os = "ios",
404-
target_os = "tvos",
405-
target_os = "watchos",
406-
target_os = "visionos"
407-
))]
398+
#[cfg(target_vendor = "apple")]
408399
const KERN_SUCCESS: libc::c_int = 0;
409400

410-
#[cfg(any(
411-
target_os = "macos",
412-
target_os = "ios",
413-
target_os = "tvos",
414-
target_os = "watchos",
415-
target_os = "visionos"
416-
))]
401+
#[cfg(target_vendor = "apple")]
417402
#[repr(C)]
418403
struct mach_timebase_info_type {
419404
numer: u32,
420405
denom: u32,
421406
}
422407

423-
#[cfg(any(
424-
target_os = "macos",
425-
target_os = "ios",
426-
target_os = "tvos",
427-
target_os = "watchos",
428-
target_os = "visionos"
429-
))]
408+
#[cfg(target_vendor = "apple")]
430409
extern "C" {
431410
fn mach_wait_until(deadline: u64) -> libc::c_int;
432411
fn mach_timebase_info(info: *mut mach_timebase_info_type) -> libc::c_int;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::os::windows::io::{AsRawHandle, HandleOrNull};
1919
use crate::sys::handle::Handle;
2020
use crate::sys::{c, stack_overflow};
2121
use crate::sys_common::FromInner;
22-
use crate::time::Duration;
22+
use crate::time::{Duration, Instant};
2323
use crate::{io, ptr};
2424

2525
pub const DEFAULT_MIN_STACK_SIZE: usize = 2 * 1024 * 1024;
@@ -120,7 +120,7 @@ impl Thread {
120120
let now = Instant::now();
121121

122122
if let Some(delay) = deadline.checked_duration_since(now) {
123-
sleep(delay);
123+
Self::sleep(delay);
124124
}
125125
}
126126

library/std/src/thread/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,9 @@ pub fn sleep(dur: Duration) {
894894
/// | Android | [clock_nanosleep] (Monotonic Clock)] |
895895
/// | Solaris | [clock_nanosleep] (Monotonic Clock)] |
896896
/// | Illumos | [clock_nanosleep] (Monotonic Clock)] |
897+
/// | Dragonfly | [clock_nanosleep] (Monotonic Clock)] |
898+
/// | Hurd | [clock_nanosleep] (Monotonic Clock)] |
899+
/// | Fuchsia | [clock_nanosleep] (Monotonic Clock)] |
897900
/// | Darwin | [mach_wait_until] |
898901
/// | WASI | [subscription_clock] |
899902
/// | Other | `sleep_until` uses [`sleep`] and does not issue a syscall itself |

0 commit comments

Comments
 (0)