Skip to content

Commit e9c6735

Browse files
mutantbobRobert Forsman
andauthored
fix AVR support by using atomic-polyfill (#124)
* 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>
1 parent b526344 commit e9c6735

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ runtime-rng = ["getrandom"]
3636
# If this is disabled and runtime-rng is unavailable constant keys are used.
3737
compile-time-rng = ["const-random"]
3838

39+
# in case this is being used on an architecture lacking core::sync::atomic::AtomicUsize and friends
40+
atomic-polyfill = [ "dep:atomic-polyfill", "once_cell/atomic-polyfill"]
41+
3942
[[bench]]
4043
name = "ahash"
4144
path = "tests/bench.rs"
@@ -71,6 +74,7 @@ version_check = "0.9.4"
7174
const-random = { version = "0.1.12", optional = true }
7275
serde = { version = "1.0.117", optional = true }
7376
cfg-if = "1.0"
77+
atomic-polyfill = { version="1.0.1", optional=true}
7478

7579
[target."cfg(not(any(target_arch = \"wasm32\", target_abi = \"unknown\")))".dependencies.getrandom]
7680
version = "0.2.7"
@@ -81,7 +85,7 @@ version = "0.2.7"
8185
features = ["js"]
8286

8387
[target.'cfg(not(all(target_arch = "arm", target_os = "none")))'.dependencies]
84-
once_cell = { version = "1.8", default-features = false, features = ["unstable", "alloc"] }
88+
once_cell = { version = "1.13.1", default-features = false, features = ["unstable", "alloc"] }
8589

8690
[dev-dependencies]
8791
no-panic = "0.1.10"

src/random_state.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ cfg_if::cfg_if! {
2323
}
2424
}
2525

26+
#[cfg(feature = "atomic-polyfill")]
27+
use atomic_polyfill as atomic;
28+
#[cfg(not(feature = "atomic-polyfill"))]
29+
use core::sync::atomic;
30+
2631
use alloc::boxed::Box;
27-
use core::sync::atomic::{AtomicUsize, Ordering};
32+
use atomic::{AtomicUsize, Ordering};
2833
use core::any::{Any, TypeId};
2934
use core::fmt;
3035
use core::hash::BuildHasher;

0 commit comments

Comments
 (0)