From 42e9c7933a82c6bab74fa1dd992374b9340a4e0f Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 7 Sep 2022 07:24:16 +0200 Subject: [PATCH] Always use `atomic-polyfill` with `critical-section` implementation. --- Cargo.toml | 2 +- src/imp_cs.rs | 18 ++---------------- xtask/src/main.rs | 7 ------- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a771bc4..67bb98e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,7 +56,7 @@ sync = [] parking_lot = ["parking_lot_core"] -critical-section = ["critical_section", "sync"] +critical-section = ["critical_section", "atomic-polyfill", "sync"] [[example]] name = "bench" diff --git a/src/imp_cs.rs b/src/imp_cs.rs index a1abede..9cc98ec 100644 --- a/src/imp_cs.rs +++ b/src/imp_cs.rs @@ -1,13 +1,11 @@ use core::panic::{RefUnwindSafe, UnwindSafe}; -#[cfg(feature = "atomic-polyfill")] use atomic_polyfill::{AtomicBool, Ordering}; use critical_section::{CriticalSection, Mutex}; use crate::unsync::OnceCell as UnsyncOnceCell; pub(crate) struct OnceCell { - #[cfg(feature = "atomic-polyfill")] initialized: AtomicBool, value: Mutex>, } @@ -25,16 +23,11 @@ impl UnwindSafe for OnceCell {} impl OnceCell { pub(crate) const fn new() -> OnceCell { - OnceCell { - #[cfg(feature = "atomic-polyfill")] - initialized: AtomicBool::new(false), - value: Mutex::new(UnsyncOnceCell::new()), - } + OnceCell { initialized: AtomicBool::new(false), value: Mutex::new(UnsyncOnceCell::new()) } } pub(crate) const fn with_value(value: T) -> OnceCell { OnceCell { - #[cfg(feature = "atomic-polyfill")] initialized: AtomicBool::new(true), value: Mutex::new(UnsyncOnceCell::with_value(value)), } @@ -42,13 +35,7 @@ impl OnceCell { #[inline] pub(crate) fn is_initialized(&self) -> bool { - #[cfg(feature = "atomic-polyfill")] - { - self.initialized.load(Ordering::Acquire) - } - - #[cfg(not(feature = "atomic-polyfill"))] - critical_section::with(|cs| self.value.borrow(cs).get().is_some()) + self.initialized.load(Ordering::Acquire) } #[cold] @@ -59,7 +46,6 @@ impl OnceCell { critical_section::with(|cs| { let cell = self.value.borrow(cs); cell.get_or_try_init(f).map(|_| { - #[cfg(feature = "atomic-polyfill")] self.initialized.store(true, Ordering::Release); () diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 7ef0642..076c782 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -46,13 +46,6 @@ fn try_main() -> Result<()> { "cargo test --features 'unstable std critical-section' --no-default-features --release" ) .run()?; - - cmd!("cargo test --features 'unstable std atomic-polyfill critical-section' --no-default-features") - .run()?; - cmd!( - "cargo test --features 'unstable std atomic-polyfill critical-section' --no-default-features --release" - ) - .run()?; } {