x86: put Sync impl behind a Cargo feature

This commit is contained in:
Jorge Aparicio 2020-05-03 17:07:46 +02:00
parent af877b4418
commit ea0c189a62
4 changed files with 24 additions and 6 deletions

View File

@ -23,6 +23,8 @@ version = "0.5.4"
default = ["cas"]
cas = []
ufmt-impl = ["ufmt-write"]
# read the docs before enabling: makes `Pool` Sync on x86_64
x86-sync-pool = []
# only for tests
__trybuild = []

View File

@ -5,8 +5,8 @@ main() {
cargo check --target $TARGET --features 'serde'
if [ $TARGET = x86_64-unknown-linux-gnu ]; then
cargo test --target $TARGET --features 'serde'
cargo test --target $TARGET --release --features 'serde'
cargo test --test cpass --target $TARGET --features 'serde'
cargo test --test cpass --target $TARGET --release --features 'serde'
if [ $MSRV = 1 ]; then
cd cfail
@ -19,8 +19,8 @@ main() {
export RUSTFLAGS="-Z sanitizer=thread"
export TSAN_OPTIONS="suppressions=$(pwd)/suppressions.txt"
cargo test --test tsan --target $TARGET
cargo test --test tsan --target $TARGET --release
cargo test --test tsan --features x86-sync-pool --target $TARGET
cargo test --test tsan --features x86-sync-pool --target $TARGET --release
fi
fi
}

View File

@ -153,6 +153,8 @@
//!
//! # x86_64 support / limitations
//!
//! *NOTE* `Pool` is only `Sync` on `x86_64` if the Cargo feature "x86-sync-pool" is enabled
//!
//! x86_64 support is a gamble. Yes, a gamble. Do you feel lucky enough to use `Pool` on x86_64?
//!
//! 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> {
_not_send_or_sync: PhantomData<*const ()>,
}
#[cfg(any(armv7a, armv7r, armv7m, armv8m_main, target_arch = "x86_64"))]
// NOTE(any(test)) makes testing easier (no need to enable Cargo features for testing)
#[cfg(any(
armv7a,
armv7r,
armv7m,
armv8m_main,
all(target_arch = "x86_64", feature = "x86-sync-pool"),
test
))]
unsafe impl<T> Sync for Pool<T> {}
unsafe impl<T> Send for Pool<T> {}

View File

@ -15,7 +15,13 @@ use as_slice::{AsMutSlice, AsSlice};
use super::{Init, Node, Uninit};
/// Instantiates a pool as a global singleton
#[cfg(any(armv7a, armv7r, armv7m, armv8m_main, target_arch = "x86_64"))]
#[cfg(any(
armv7a,
armv7r,
armv7m,
armv8m_main,
all(target_arch = "x86_64", feature = "x86-sync-pool"),
))]
#[macro_export]
macro_rules! pool {
($(#[$($attr:tt)*])* $ident:ident: $ty:ty) => {