| 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 | 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 | } else if #[cfg(any( |
| 25 | windows, |
| 26 | target_family = "unix" , |
| 27 | all(target_vendor = "fortanix" , target_env = "sgx" ), |
| 28 | target_os = "solid_asp3" , |
| 29 | target_os = "xous" , |
| 30 | ))] { |
| 31 | mod queue; |
| 32 | pub use queue::{Once, OnceState}; |
| 33 | } else { |
| 34 | mod no_threads; |
| 35 | pub use no_threads::{Once, OnceState}; |
| 36 | } |
| 37 | } |
| 38 | |