diff --git a/Cargo.toml b/Cargo.toml index 16ef966..1cf765a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,15 +19,15 @@ name = "string_cache" [features] serde_support = ["serde"] -default = ["serde_support"] - +default = ["serde_support", "parking_lot_support"] +parking_lot_support = ["parking_lot"] [dependencies] precomputed-hash = "0.1" once_cell = "1.10.0" serde = { version = "1", optional = true } phf_shared = "0.10" new_debug_unreachable = "1.0.2" -parking_lot = "0.12" +parking_lot = { version = "0.12", optional = true} [[test]] name = "small-stack" diff --git a/src/atom.rs b/src/atom.rs index c02651b..9e96b6f 100644 --- a/src/atom.rs +++ b/src/atom.rs @@ -200,8 +200,13 @@ impl<'a, Static: StaticAtomSet> From> for Atom { phantom: PhantomData, } } else { + #[cfg(feature = "parking_lot_support")] let ptr: std::ptr::NonNull = DYNAMIC_SET.lock().insert(string_to_add, hash.g); + + #[cfg(not(feature = "parking_lot_support"))] + let ptr: std::ptr::NonNull = + DYNAMIC_SET.lock().unwrap().insert(string_to_add, hash.g); let data = ptr.as_ptr() as u64; debug_assert!(0 == data & TAG_MASK); Atom { @@ -237,6 +242,12 @@ impl Drop for Atom { // Out of line to guide inlining. fn drop_slow(this: &mut Atom) { + #[cfg(not(feature = "parking_lot_support"))] + DYNAMIC_SET + .lock() + .unwrap() + .remove(this.unsafe_data.get() as *mut Entry); + #[cfg(feature = "parking_lot_support")] DYNAMIC_SET .lock() .remove(this.unsafe_data.get() as *mut Entry); diff --git a/src/dynamic_set.rs b/src/dynamic_set.rs index 229a79f..87b6141 100644 --- a/src/dynamic_set.rs +++ b/src/dynamic_set.rs @@ -8,12 +8,15 @@ // except according to those terms. use once_cell::sync::Lazy; +#[cfg(feature = "parking_lot_support")] use parking_lot::Mutex; use std::borrow::Cow; use std::mem; use std::ptr::NonNull; use std::sync::atomic::AtomicIsize; use std::sync::atomic::Ordering::SeqCst; +#[cfg(not(feature = "parking_lot_support"))] +use std::sync::Mutex; const NB_BUCKETS: usize = 1 << 12; // 4096 const BUCKET_MASK: u32 = (1 << 12) - 1;