From b6e35cc1ac39f66502e7b7968b82582cfcca6bd5 Mon Sep 17 00:00:00 2001 From: Ilya Ostrovskiy Date: Mon, 3 Oct 2022 17:14:55 -0400 Subject: [PATCH 1/2] support atomic-polyfill for environments without native atomics --- Cargo.toml | 2 ++ src/loom.rs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index bd6ebfd7f..89f52a7de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,9 +20,11 @@ edition = "2018" [features] default = ["std"] std = [] +atomic-polyfill = ["dep: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..a1028f544 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 = "atomic-polyfill"))] pub(crate) use core::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; + #[cfg(feature = "atomic-polyfill")] + pub(crate) use atomic_polyfill::{AtomicPtr, AtomicUsize, Ordering}; + pub(crate) trait AtomicMut { fn with_mut(&mut self, f: F) -> R where From 1bd9ed54e5f9e5fefbdce1c235f66d6c2c4759a5 Mon Sep 17 00:00:00 2001 From: Ilya Ostrovskiy Date: Mon, 3 Oct 2022 17:39:04 -0400 Subject: [PATCH 2/2] rename feature to use-atomic-polyfill to avoid depending on nightly features --- Cargo.toml | 2 +- src/loom.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 89f52a7de..b7750b3f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ edition = "2018" [features] default = ["std"] std = [] -atomic-polyfill = ["dep:atomic-polyfill"] +use-atomic-polyfill = ["atomic-polyfill"] [dependencies] serde = { version = "1.0.60", optional = true, default-features = false, features = ["alloc"] } diff --git a/src/loom.rs b/src/loom.rs index a1028f544..79ca4ceae 100644 --- a/src/loom.rs +++ b/src/loom.rs @@ -1,10 +1,10 @@ #[cfg(not(all(test, loom)))] pub(crate) mod sync { pub(crate) mod atomic { - #[cfg(not(feature = "atomic-polyfill"))] + #[cfg(not(feature = "use-atomic-polyfill"))] pub(crate) use core::sync::atomic::{AtomicPtr, AtomicUsize, Ordering}; - #[cfg(feature = "atomic-polyfill")] + #[cfg(feature = "use-atomic-polyfill")] pub(crate) use atomic_polyfill::{AtomicPtr, AtomicUsize, Ordering}; pub(crate) trait AtomicMut {