From 449e5d7b2d57ca101e364a0596e84c792a78d674 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Mon, 23 Sep 2024 05:58:38 +0900 Subject: [PATCH] Add portable-atomic feature and disable portable-atomic/critical-section by default --- Cargo.lock.msrv | 3 --- Cargo.toml | 14 ++++++++++---- src/race.rs | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Cargo.lock.msrv b/Cargo.lock.msrv index e2b0243..9da533e 100644 --- a/Cargo.lock.msrv +++ b/Cargo.lock.msrv @@ -69,9 +69,6 @@ name = "portable-atomic" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" -dependencies = [ - "critical-section", -] [[package]] name = "redox_syscall" diff --git a/Cargo.toml b/Cargo.toml index e59b414..54954f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ members = ["xtask"] [dependencies] parking_lot_core = { version = "0.9.10", optional = true, default-features = false } -portable-atomic = { version = "1.7", optional = true } +portable-atomic = { version = "1.7", optional = true, default-features = false } critical-section = { version = "1.1.3", optional = true } [dev-dependencies] @@ -38,17 +38,23 @@ std = ["alloc"] alloc = ["race"] # Enables `once_cell::race` module. -race = [] +race = ["portable-atomic?/require-cas"] # Uses parking_lot to implement once_cell::sync::OnceCell. # This makes no speed difference, but makes each OnceCell # up to 16 bytes smaller, depending on the size of the T. parking_lot = ["dep:parking_lot_core"] -# Uses `critical-section` to implement `sync` and `race` modules. in +# Uses `portable-atomic` to implement `race` module. in +# `#![no_std]` mode. Please read `portable-atomic` docs carefully +# before enabling this feature. +portable-atomic = ["dep:portable-atomic"] + +# Uses `critical-section` to implement `sync` module. in # `#![no_std]` mode. Please read `critical-section` docs carefully # before enabling this feature. -critical-section = ["dep:critical-section", "portable-atomic/critical-section"] +# `portable-atomic` feature is enabled for backwards compatibility. +critical-section = ["dep:critical-section", "portable-atomic"] # Enables semver-exempt APIs of this crate. # At the moment, this feature is unused. diff --git a/src/race.rs b/src/race.rs index 89e4367..9c09323 100644 --- a/src/race.rs +++ b/src/race.rs @@ -19,9 +19,9 @@ //! `Acquire` and `Release` have very little performance overhead on most //! architectures versus `Relaxed`. -#[cfg(not(feature = "critical-section"))] +#[cfg(not(feature = "portable-atomic"))] use core::sync::atomic; -#[cfg(feature = "critical-section")] +#[cfg(feature = "portable-atomic")] use portable_atomic as atomic; use atomic::{AtomicPtr, AtomicUsize, Ordering};