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

Replace lazy_static with once_cell #817

Merged
merged 1 commit into from May 1, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 3 additions & 9 deletions crossbeam-epoch/Cargo.toml
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
#
Expand All @@ -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"
12 changes: 10 additions & 2 deletions crossbeam-epoch/src/default.rs
Expand Up @@ -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<Collector> = Lazy::new(Collector::new);
// FIXME: loom does not currently provide the equivalent of Lazy:
// https://github.com/tokio-rs/loom/issues/263
#[cfg(crossbeam_loom)]
loom::lazy_static! {
/// The global data for the default garbage collector.
static ref COLLECTOR: Collector = Collector::new();
}
Expand Down
4 changes: 0 additions & 4 deletions crossbeam-epoch/src/lib.rs
Expand Up @@ -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))]
Expand Down Expand Up @@ -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))]
Expand Down
4 changes: 2 additions & 2 deletions crossbeam-utils/Cargo.toml
Expand Up @@ -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.
Expand All @@ -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.
#
Expand Down
10 changes: 5 additions & 5 deletions crossbeam-utils/src/sync/sharded_lock.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -583,13 +583,13 @@ struct ThreadIndices {
next_index: usize,
}

lazy_static! {
static ref THREAD_INDICES: Mutex<ThreadIndices> = Mutex::new(ThreadIndices {
static THREAD_INDICES: Lazy<Mutex<ThreadIndices>> = Lazy::new(|| {
Mutex::new(ThreadIndices {
mapping: HashMap::new(),
free_list: Vec::new(),
next_index: 0,
});
}
})
});

/// A registration of a thread with an index.
///
Expand Down