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 = "motor",
18        target_os = "openbsd",
19        target_os = "dragonfly",
20        target_os = "fuchsia",
21        target_os = "hermit",
22    ) => {
23        mod futex;
24        pub use futex::{Once, OnceState};
25    }
26    any(
27        windows,
28        target_family = "unix",
29        all(target_vendor = "fortanix", target_env = "sgx"),
30        target_os = "solid_asp3",
31        target_os = "xous",
32    ) => {
33        mod queue;
34        pub use queue::{Once, OnceState};
35    }
36    _ => {
37        mod no_threads;
38        pub use no_threads::{Once, OnceState};
39    }
40}