std/sys/sync/once/mod.rs
1// A "once" is a relatively simple primitive, and it's also typically provided
2// by the OS as well (see `pthread_once` or `InitOnceExecuteOnce`). The OS
3// primitives, however, tend to have surprising restrictions, such as the Unix
4// one doesn't allow an argument to be passed to the function.
5//
6// As a result, we end up implementing it ourselves in the standard library.
7// This also gives us the opportunity to optimize the implementation a bit which
8// should help the fast path on call sites.
9
10cfg_select! {
11 any(
12 all(target_os = "windows", not(target_vendor="win7")),
13 target_os = "linux",
14 target_os = "android",
15 all(target_arch = "wasm32", target_feature = "atomics"),
16 target_os = "freebsd",
17 target_os = "openbsd",
18 target_os = "dragonfly",
19 target_os = "fuchsia",
20 target_os = "hermit",
21 ) => {
22 mod futex;
23 pub use futex::{Once, OnceState};
24 }
25 any(
26 windows,
27 target_family = "unix",
28 all(target_vendor = "fortanix", target_env = "sgx"),
29 target_os = "solid_asp3",
30 target_os = "xous",
31 ) => {
32 mod queue;
33 pub use queue::{Once, OnceState};
34 }
35 _ => {
36 mod no_threads;
37 pub use no_threads::{Once, OnceState};
38 }
39}