1cfg_select! {
2 target_os = "hermit" => {
3 mod hermit;
4 pub use hermit::{Thread, available_parallelism, sleep, yield_now, DEFAULT_MIN_STACK_SIZE};
5 #[expect(dead_code)]
6 mod unsupported;
7 pub use unsupported::{current_os_id, set_name};
8 }
9 target_os = "motor" => {
10 mod motor;
11 pub use motor::*;
12 }
13 all(target_vendor = "fortanix", target_env = "sgx") => {
14 mod sgx;
15 pub use sgx::{Thread, current_os_id, sleep, yield_now, DEFAULT_MIN_STACK_SIZE};
16
17 #[expect(dead_code)]
27 mod unsupported;
28 pub use unsupported::{available_parallelism, set_name};
29 }
30 target_os = "solid_asp3" => {
31 mod solid;
32 pub use solid::{Thread, sleep, yield_now, DEFAULT_MIN_STACK_SIZE};
33 #[expect(dead_code)]
34 mod unsupported;
35 pub use unsupported::{available_parallelism, current_os_id, set_name};
36 }
37 target_os = "teeos" => {
38 mod teeos;
39 pub use teeos::{Thread, sleep, yield_now, DEFAULT_MIN_STACK_SIZE};
40 #[expect(dead_code)]
41 mod unsupported;
42 pub use unsupported::{available_parallelism, current_os_id, set_name};
43 }
44 target_os = "uefi" => {
45 mod uefi;
46 pub use uefi::{available_parallelism, sleep};
47 #[expect(dead_code)]
48 mod unsupported;
49 pub use unsupported::{Thread, current_os_id, set_name, yield_now, DEFAULT_MIN_STACK_SIZE};
50 }
51 target_family = "unix" => {
52 mod unix;
53 pub use unix::{Thread, available_parallelism, current_os_id, sleep, yield_now, DEFAULT_MIN_STACK_SIZE};
54 #[cfg(not(any(
55 target_env = "newlib",
56 target_os = "l4re",
57 target_os = "emscripten",
58 target_os = "redox",
59 target_os = "hurd",
60 target_os = "aix",
61 )))]
62 pub use unix::set_name;
63 #[cfg(any(
64 target_os = "freebsd",
65 target_os = "netbsd",
66 target_os = "linux",
67 target_os = "android",
68 target_os = "solaris",
69 target_os = "illumos",
70 target_os = "dragonfly",
71 target_os = "hurd",
72 target_os = "fuchsia",
73 target_os = "vxworks",
74 ))]
75 pub use unix::sleep_until;
76 #[expect(dead_code)]
77 mod unsupported;
78 #[cfg(any(
79 target_env = "newlib",
80 target_os = "l4re",
81 target_os = "emscripten",
82 target_os = "redox",
83 target_os = "hurd",
84 target_os = "aix",
85 ))]
86 pub use unsupported::set_name;
87 }
88 target_os = "vexos" => {
89 mod vexos;
90 pub use vexos::{sleep, yield_now};
91 #[expect(dead_code)]
92 mod unsupported;
93 pub use unsupported::{Thread, available_parallelism, current_os_id, set_name, DEFAULT_MIN_STACK_SIZE};
94 }
95 all(target_os = "wasi", target_env = "p1") => {
96 mod wasip1;
97 pub use wasip1::{DEFAULT_MIN_STACK_SIZE, sleep, yield_now};
98 #[cfg(target_feature = "atomics")]
99 pub use wasip1::{Thread, available_parallelism};
100 #[expect(dead_code)]
101 mod unsupported;
102 pub use unsupported::{current_os_id, set_name};
103 #[cfg(not(target_feature = "atomics"))]
104 pub use unsupported::{Thread, available_parallelism};
105 }
106 all(target_os = "wasi", any(target_env = "p2", target_env = "p3")) => {
107 mod wasip2;
108 pub use wasip2::{sleep, sleep_until};
109 #[expect(dead_code)]
110 mod unsupported;
111 pub use unsupported::{Thread, available_parallelism, current_os_id, set_name, yield_now, DEFAULT_MIN_STACK_SIZE};
115 }
116 all(target_family = "wasm", target_feature = "atomics") => {
117 mod wasm;
118 pub use wasm::sleep;
119
120 #[expect(dead_code)]
121 mod unsupported;
122 pub use unsupported::{Thread, available_parallelism, current_os_id, set_name, yield_now, DEFAULT_MIN_STACK_SIZE};
123 }
124 target_os = "windows" => {
125 mod windows;
126 pub use windows::{Thread, available_parallelism, current_os_id, set_name, set_name_wide, sleep, yield_now, DEFAULT_MIN_STACK_SIZE};
127 }
128 target_os = "xous" => {
129 mod xous;
130 pub use xous::{Thread, available_parallelism, sleep, yield_now, DEFAULT_MIN_STACK_SIZE};
131
132 #[expect(dead_code)]
133 mod unsupported;
134 pub use unsupported::{current_os_id, set_name};
135 }
136 _ => {
137 mod unsupported;
138 pub use unsupported::{Thread, available_parallelism, current_os_id, set_name, sleep, yield_now, DEFAULT_MIN_STACK_SIZE};
139 }
140}
141
142#[cfg(not(any(
143 target_os = "freebsd",
144 target_os = "netbsd",
145 target_os = "linux",
146 target_os = "android",
147 target_os = "solaris",
148 target_os = "illumos",
149 target_os = "dragonfly",
150 target_os = "hurd",
151 target_os = "fuchsia",
152 target_os = "vxworks",
153 all(target_os = "wasi", not(target_env = "p1")),
154)))]
155pub fn sleep_until(deadline: crate::time::Instant) {
156 use crate::time::Instant;
157
158 let now = Instant::now();
159
160 if let Some(delay) = deadline.checked_duration_since(now) {
161 sleep(delay);
162 }
163}