diff --git a/crossbeam-epoch/Cargo.toml b/crossbeam-epoch/Cargo.toml index b9aacdcbb..fe111e720 100644 --- a/crossbeam-epoch/Cargo.toml +++ b/crossbeam-epoch/Cargo.toml @@ -19,7 +19,7 @@ default = ["std"] # Enable to use APIs that require `std`. # This is enabled by default. -std = ["alloc", "crossbeam-utils/std", "lazy_static"] +std = ["alloc", "crossbeam-utils/std", "once_cell"] # Enable to use APIs that require `alloc`. # This is enabled by default and also enabled if the `std` feature is enabled. @@ -48,6 +48,8 @@ autocfg = "1" [dependencies] cfg-if = "1" memoffset = "0.6" +once_cell = { version = "1", optional = true } +scopeguard = { version = "1.1", default-features = false } # Enable the use of loom for concurrency testing. # @@ -61,14 +63,6 @@ version = "0.8.5" path = "../crossbeam-utils" default-features = false -[dependencies.lazy_static] -version = "1.4.0" -optional = true - -[dependencies.scopeguard] -version = "1.1.0" -default-features = false - [dev-dependencies] rand = "0.8" rustversion = "1" diff --git a/crossbeam-epoch/src/default.rs b/crossbeam-epoch/src/default.rs index b7797ce96..180a791c9 100644 --- a/crossbeam-epoch/src/default.rs +++ b/crossbeam-epoch/src/default.rs @@ -6,9 +6,17 @@ use crate::collector::{Collector, LocalHandle}; use crate::guard::Guard; -use crate::primitive::{lazy_static, thread_local}; +use crate::primitive::thread_local; +#[cfg(not(crossbeam_loom))] +use once_cell::sync::Lazy; -lazy_static! { +/// The global data for the default garbage collector. +#[cfg(not(crossbeam_loom))] +static COLLECTOR: Lazy = Lazy::new(Collector::new); +// FIXME: loom does not currently provide the equivalent of Lazy: +// https://github.com/crossbeam-rs/crossbeam/issues/623 +#[cfg(crossbeam_loom)] +loom::lazy_static! { /// The global data for the default garbage collector. static ref COLLECTOR: Collector = Collector::new(); } diff --git a/crossbeam-epoch/src/lib.rs b/crossbeam-epoch/src/lib.rs index 7150ec6f7..4cf982b6b 100644 --- a/crossbeam-epoch/src/lib.rs +++ b/crossbeam-epoch/src/lib.rs @@ -88,7 +88,6 @@ mod primitive { } pub(crate) use loom::sync::Arc; } - pub(crate) use loom::lazy_static; pub(crate) use loom::thread_local; } #[cfg(not(crossbeam_no_atomic_cas))] @@ -135,9 +134,6 @@ mod primitive { #[cfg(feature = "std")] pub(crate) use std::thread_local; - - #[cfg(feature = "std")] - pub(crate) use lazy_static::lazy_static; } #[cfg(not(crossbeam_no_atomic_cas))] diff --git a/crossbeam-utils/Cargo.toml b/crossbeam-utils/Cargo.toml index 0c2eebf1b..5b0849c1a 100644 --- a/crossbeam-utils/Cargo.toml +++ b/crossbeam-utils/Cargo.toml @@ -19,7 +19,7 @@ default = ["std"] # Enable to use APIs that require `std`. # This is enabled by default. -std = ["lazy_static"] +std = ["once_cell"] # These features are no longer used. # TODO: remove in the next major version. @@ -32,7 +32,7 @@ nightly = [] [dependencies] cfg-if = "1" -lazy_static = { version = "1.4.0", optional = true } +once_cell = { version = "1", optional = true } # Enable the use of loom for concurrency testing. # diff --git a/crossbeam-utils/src/sync/sharded_lock.rs b/crossbeam-utils/src/sync/sharded_lock.rs index 163d34c81..692653447 100644 --- a/crossbeam-utils/src/sync/sharded_lock.rs +++ b/crossbeam-utils/src/sync/sharded_lock.rs @@ -10,7 +10,7 @@ use std::sync::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard}; use std::thread::{self, ThreadId}; use crate::CachePadded; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; /// The number of shards per sharded lock. Must be a power of two. const NUM_SHARDS: usize = 8; @@ -583,13 +583,13 @@ struct ThreadIndices { next_index: usize, } -lazy_static! { - static ref THREAD_INDICES: Mutex = Mutex::new(ThreadIndices { +static THREAD_INDICES: Lazy> = Lazy::new(|| { + Mutex::new(ThreadIndices { mapping: HashMap::new(), free_list: Vec::new(), next_index: 0, - }); -} + }) +}); /// A registration of a thread with an index. ///