From afe8e2a4969e2c94f57eef0a2ad21906e69052dc Mon Sep 17 00:00:00 2001 From: Robert Forsman Date: Fri, 19 Aug 2022 14:21:53 -0400 Subject: [PATCH 1/2] use atomic-polyfill for architectures lacking AtomicUsize --- Cargo.toml | 4 ++++ src/random_state.rs | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4b56472..ebc54f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,9 @@ std = [] # If this is disabled and gerrandom 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"] + [[bench]] name = "ahash" path = "tests/bench.rs" @@ -72,6 +75,7 @@ serde = { version = "1.0.117", optional = true } [target.'cfg(not(any(target_os = "linux", target_os = "android", target_os = "windows", target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", target_os = "dragonfly", target_os = "solaris", target_os = "illumos", target_os = "fuchsia", target_os = "redox", target_os = "cloudabi", target_os = "haiku", target_os = "vxworks", target_os = "emscripten", target_os = "wasi")))'.dependencies] const-random = { version = "0.1.12", optional = true } serde = { version = "1.0.117", optional = true } +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 = ["alloc"] } diff --git a/src/random_state.rs b/src/random_state.rs index c3628bf..2d88518 100644 --- a/src/random_state.rs +++ b/src/random_state.rs @@ -30,7 +30,12 @@ extern crate alloc; extern crate std as alloc; use alloc::boxed::Box; -use core::sync::atomic::{AtomicUsize, Ordering}; + +#[cfg(feature = "atomic-polyfill")] +use atomic_polyfill as atomic; +#[cfg(not(feature = "atomic-polyfill"))] +use core::sync::atomic; +use atomic::{AtomicUsize, Ordering}; #[cfg(not(all(target_arch = "arm", target_os = "none")))] use once_cell::race::OnceBox; From 1e96805e361b32134574825de2061619fb430081 Mon Sep 17 00:00:00 2001 From: Robert Forsman Date: Thu, 25 Aug 2022 12:29:03 -0400 Subject: [PATCH 2/2] propagate the atomic-polyfill feature to the once_cell dependency --- Cargo.toml | 4 ++-- src/random_state.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ebc54f2..21a1b81 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ std = [] 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"] +atomic-polyfill = [ "dep:atomic-polyfill", "once_cell/atomic-polyfill"] [[bench]] name = "ahash" @@ -78,7 +78,7 @@ serde = { version = "1.0.117", optional = true } 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 = ["alloc"] } +once_cell = { version = "1.13.1", default-features = false, features = ["alloc"] } [dev-dependencies] no-panic = "0.1.10" diff --git a/src/random_state.rs b/src/random_state.rs index 2d88518..9ac2f3e 100644 --- a/src/random_state.rs +++ b/src/random_state.rs @@ -29,12 +29,12 @@ extern crate alloc; #[cfg(feature = "std")] extern crate std as alloc; -use alloc::boxed::Box; - #[cfg(feature = "atomic-polyfill")] use atomic_polyfill as atomic; #[cfg(not(feature = "atomic-polyfill"))] use core::sync::atomic; + +use alloc::boxed::Box; use atomic::{AtomicUsize, Ordering}; #[cfg(not(all(target_arch = "arm", target_os = "none")))] use once_cell::race::OnceBox;