diff --git a/Cargo.toml b/Cargo.toml index 6a0093a..bd19c63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,9 @@ runtime-rng = ["getrandom"] # If this is disabled and runtime-rng is unavailable constant keys are used. compile-time-rng = ["const-random"] +# in case this is being used on an architecture lacking core::sync::atomic::AtomicUsize and friends +atomic-polyfill = [ "dep:atomic-polyfill", "once_cell/atomic-polyfill"] + [[bench]] name = "ahash" path = "tests/bench.rs" @@ -72,9 +75,10 @@ getrandom = { version = "0.2.3", optional = true } const-random = { version = "0.1.12", optional = true } serde = { version = "1.0.117", optional = true } cfg-if = "1.0" +atomic-polyfill = { version="1.0.1", optional=true} [target.'cfg(not(all(target_arch = "arm", target_os = "none")))'.dependencies] -once_cell = { version = "1.8", default-features = false, features = ["unstable", "alloc"] } +once_cell = { version = "1.13.1", default-features = false, features = ["unstable", "alloc"] } [dev-dependencies] no-panic = "0.1.10" diff --git a/src/random_state.rs b/src/random_state.rs index b750bcd..d7c5c70 100644 --- a/src/random_state.rs +++ b/src/random_state.rs @@ -23,8 +23,13 @@ cfg_if::cfg_if! { } } +#[cfg(feature = "atomic-polyfill")] +use atomic_polyfill as atomic; +#[cfg(not(feature = "atomic-polyfill"))] +use core::sync::atomic; + use alloc::boxed::Box; -use core::sync::atomic::{AtomicUsize, Ordering}; +use atomic::{AtomicUsize, Ordering}; use core::any::{Any, TypeId}; use core::fmt; use core::hash::BuildHasher;