Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add portable-atomic feature and disable portable-atomic/critical-section by default #265

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Cargo.lock.msrv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -38,17 +38,23 @@ std = ["alloc"]
alloc = ["race"]

# Enables `once_cell::race` module.
race = []
race = ["portable-atomic?/require-cas"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, due to Cargo bug (rust-lang/cargo#10801), this makes portable-atomic to appear in Cargo.lock (even if the portable-atomic feature is not enabled. even if portable-atomic will never be compiled).

With the diagnostic improvements in portable-atomic 1.8 (taiki-e/portable-atomic#181), the need for require-cas feature has decreased, so I think it is probably fine to remove "portable-atomic?/require-cas"...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also fine with keeping it! Cargo bug is a bug, the code here seems correct, and could perhaps be helpful for older versions of portable-atomic?

I guess you are the best person to make a judgement call here though :)


# Uses parking_lot to implement once_cell::sync::OnceCell.
# This makes no speed difference, but makes each OnceCell<T>
# 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.
Expand Down
4 changes: 2 additions & 2 deletions src/race.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Loading