Skip to content

Commit

Permalink
fix AVR support by using atomic-polyfill (#124)
Browse files Browse the repository at this point in the history
* use atomic-polyfill for architectures lacking AtomicUsize
* propagate the atomic-polyfill feature to the once_cell dependency

Co-authored-by: Robert Forsman <git@thoth.purplefrog.com>
  • Loading branch information
mutantbob and Robert Forsman committed Oct 23, 2022
1 parent b526344 commit e9c6735
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Expand Up @@ -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"
Expand Down Expand Up @@ -71,6 +74,7 @@ version_check = "0.9.4"
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(any(target_arch = \"wasm32\", target_abi = \"unknown\")))".dependencies.getrandom]
version = "0.2.7"
Expand All @@ -81,7 +85,7 @@ version = "0.2.7"
features = ["js"]

[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"
Expand Down
7 changes: 6 additions & 1 deletion src/random_state.rs
Expand Up @@ -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;
Expand Down

0 comments on commit e9c6735

Please sign in to comment.