• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
10 cfg_if::cfg_if! {
11     if #[cfg(any(
12         target_os = "linux",
13         target_os = "android",
14         all(target_arch = "wasm32", target_feature = "atomics"),
15         target_os = "freebsd",
16         target_os = "openbsd",
17         target_os = "dragonfly",
18         target_os = "fuchsia",
19         target_os = "hermit",
20     ))] {
21         mod futex;
22         pub use futex::{Once, OnceState};
23     } else if #[cfg(any(
24         windows,
25         target_family = "unix",
26         all(target_vendor = "fortanix", target_env = "sgx"),
27         target_os = "solid_asp3",
28     ))] {
29         mod queue;
30         pub use queue::{Once, OnceState};
31     } else {
32         pub use crate::sys::once::{Once, OnceState};
33     }
34 }
35