diff --git a/Cargo.toml b/Cargo.toml index bd6ebfd7f..b7750b3f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,11 @@ edition = "2018" [features] default = ["std"] std = [] +use-atomic-polyfill = ["atomic-polyfill"] [dependencies] serde = { version = "1.0.60", optional = true, default-features = false, features = ["alloc"] } +atomic-polyfill = { version = "1.0.1", optional = true } [dev-dependencies] serde_test = "1.0" diff --git a/src/loom.rs b/src/loom.rs index 9e6b2d5e2..79ca4ceae 100644 --- a/src/loom.rs +++ b/src/loom.rs @@ -1,8 +1,12 @@ #[cfg(not(all(test, loom)))] pub(crate) mod sync { pub(crate) mod atomic { + #[cfg(not(feature = "use-atomic-polyfill"))] pub(crate) use core::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; + #[cfg(feature = "use-atomic-polyfill")] + pub(crate) use atomic_polyfill::{AtomicPtr, AtomicUsize, Ordering}; + pub(crate) trait AtomicMut { fn with_mut(&mut self, f: F) -> R where