Skip to content

Commit ea0c189

Browse files
committed
x86: put Sync impl behind a Cargo feature
1 parent af877b4 commit ea0c189

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ version = "0.5.4"
2323
default = ["cas"]
2424
cas = []
2525
ufmt-impl = ["ufmt-write"]
26+
# read the docs before enabling: makes `Pool` Sync on x86_64
27+
x86-sync-pool = []
2628
# only for tests
2729
__trybuild = []
2830

ci/script.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ main() {
55
cargo check --target $TARGET --features 'serde'
66

77
if [ $TARGET = x86_64-unknown-linux-gnu ]; then
8-
cargo test --target $TARGET --features 'serde'
9-
cargo test --target $TARGET --release --features 'serde'
8+
cargo test --test cpass --target $TARGET --features 'serde'
9+
cargo test --test cpass --target $TARGET --release --features 'serde'
1010

1111
if [ $MSRV = 1 ]; then
1212
cd cfail
@@ -19,8 +19,8 @@ main() {
1919
export RUSTFLAGS="-Z sanitizer=thread"
2020
export TSAN_OPTIONS="suppressions=$(pwd)/suppressions.txt"
2121

22-
cargo test --test tsan --target $TARGET
23-
cargo test --test tsan --target $TARGET --release
22+
cargo test --test tsan --features x86-sync-pool --target $TARGET
23+
cargo test --test tsan --features x86-sync-pool --target $TARGET --release
2424
fi
2525
fi
2626
}

src/pool/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@
153153
//!
154154
//! # x86_64 support / limitations
155155
//!
156+
//! *NOTE* `Pool` is only `Sync` on `x86_64` if the Cargo feature "x86-sync-pool" is enabled
157+
//!
156158
//! x86_64 support is a gamble. Yes, a gamble. Do you feel lucky enough to use `Pool` on x86_64?
157159
//!
158160
//! As it's not possible to implement *ideal* LL/SC semantics (\*) on x86_64 the architecture is
@@ -253,7 +255,15 @@ pub struct Pool<T> {
253255
_not_send_or_sync: PhantomData<*const ()>,
254256
}
255257

256-
#[cfg(any(armv7a, armv7r, armv7m, armv8m_main, target_arch = "x86_64"))]
258+
// NOTE(any(test)) makes testing easier (no need to enable Cargo features for testing)
259+
#[cfg(any(
260+
armv7a,
261+
armv7r,
262+
armv7m,
263+
armv8m_main,
264+
all(target_arch = "x86_64", feature = "x86-sync-pool"),
265+
test
266+
))]
257267
unsafe impl<T> Sync for Pool<T> {}
258268

259269
unsafe impl<T> Send for Pool<T> {}

src/pool/singleton.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ use as_slice::{AsMutSlice, AsSlice};
1515
use super::{Init, Node, Uninit};
1616

1717
/// Instantiates a pool as a global singleton
18-
#[cfg(any(armv7a, armv7r, armv7m, armv8m_main, target_arch = "x86_64"))]
18+
#[cfg(any(
19+
armv7a,
20+
armv7r,
21+
armv7m,
22+
armv8m_main,
23+
all(target_arch = "x86_64", feature = "x86-sync-pool"),
24+
))]
1925
#[macro_export]
2026
macro_rules! pool {
2127
($(#[$($attr:tt)*])* $ident:ident: $ty:ty) => {

0 commit comments

Comments
 (0)