Skip to content

Commit 80804e0

Browse files
bors[bot]taiki-e
andauthored
Merge #817
817: Replace lazy_static with once_cell r=taiki-e a=taiki-e Closes #623 Co-authored-by: Taiki Endo <[email protected]>
2 parents 450d237 + 08e41e1 commit 80804e0

File tree

5 files changed

+20
-22
lines changed

5 files changed

+20
-22
lines changed

crossbeam-epoch/Cargo.toml

+3-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ default = ["std"]
1919

2020
# Enable to use APIs that require `std`.
2121
# This is enabled by default.
22-
std = ["alloc", "crossbeam-utils/std", "lazy_static"]
22+
std = ["alloc", "crossbeam-utils/std", "once_cell"]
2323

2424
# Enable to use APIs that require `alloc`.
2525
# This is enabled by default and also enabled if the `std` feature is enabled.
@@ -48,6 +48,8 @@ autocfg = "1"
4848
[dependencies]
4949
cfg-if = "1"
5050
memoffset = "0.6"
51+
once_cell = { version = "1", optional = true }
52+
scopeguard = { version = "1.1", default-features = false }
5153

5254
# Enable the use of loom for concurrency testing.
5355
#
@@ -61,14 +63,6 @@ version = "0.8.5"
6163
path = "../crossbeam-utils"
6264
default-features = false
6365

64-
[dependencies.lazy_static]
65-
version = "1.4.0"
66-
optional = true
67-
68-
[dependencies.scopeguard]
69-
version = "1.1.0"
70-
default-features = false
71-
7266
[dev-dependencies]
7367
rand = "0.8"
7468
rustversion = "1"

crossbeam-epoch/src/default.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@
66
77
use crate::collector::{Collector, LocalHandle};
88
use crate::guard::Guard;
9-
use crate::primitive::{lazy_static, thread_local};
9+
use crate::primitive::thread_local;
10+
#[cfg(not(crossbeam_loom))]
11+
use once_cell::sync::Lazy;
1012

11-
lazy_static! {
13+
/// The global data for the default garbage collector.
14+
#[cfg(not(crossbeam_loom))]
15+
static COLLECTOR: Lazy<Collector> = Lazy::new(Collector::new);
16+
// FIXME: loom does not currently provide the equivalent of Lazy:
17+
// https://github.com/tokio-rs/loom/issues/263
18+
#[cfg(crossbeam_loom)]
19+
loom::lazy_static! {
1220
/// The global data for the default garbage collector.
1321
static ref COLLECTOR: Collector = Collector::new();
1422
}

crossbeam-epoch/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ mod primitive {
8888
}
8989
pub(crate) use loom::sync::Arc;
9090
}
91-
pub(crate) use loom::lazy_static;
9291
pub(crate) use loom::thread_local;
9392
}
9493
#[cfg(not(crossbeam_no_atomic_cas))]
@@ -135,9 +134,6 @@ mod primitive {
135134

136135
#[cfg(feature = "std")]
137136
pub(crate) use std::thread_local;
138-
139-
#[cfg(feature = "std")]
140-
pub(crate) use lazy_static::lazy_static;
141137
}
142138

143139
#[cfg(not(crossbeam_no_atomic_cas))]

crossbeam-utils/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ default = ["std"]
1919

2020
# Enable to use APIs that require `std`.
2121
# This is enabled by default.
22-
std = ["lazy_static"]
22+
std = ["once_cell"]
2323

2424
# These features are no longer used.
2525
# TODO: remove in the next major version.
@@ -32,7 +32,7 @@ nightly = []
3232

3333
[dependencies]
3434
cfg-if = "1"
35-
lazy_static = { version = "1.4.0", optional = true }
35+
once_cell = { version = "1", optional = true }
3636

3737
# Enable the use of loom for concurrency testing.
3838
#

crossbeam-utils/src/sync/sharded_lock.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::sync::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard};
1010
use std::thread::{self, ThreadId};
1111

1212
use crate::CachePadded;
13-
use lazy_static::lazy_static;
13+
use once_cell::sync::Lazy;
1414

1515
/// The number of shards per sharded lock. Must be a power of two.
1616
const NUM_SHARDS: usize = 8;
@@ -583,13 +583,13 @@ struct ThreadIndices {
583583
next_index: usize,
584584
}
585585

586-
lazy_static! {
587-
static ref THREAD_INDICES: Mutex<ThreadIndices> = Mutex::new(ThreadIndices {
586+
static THREAD_INDICES: Lazy<Mutex<ThreadIndices>> = Lazy::new(|| {
587+
Mutex::new(ThreadIndices {
588588
mapping: HashMap::new(),
589589
free_list: Vec::new(),
590590
next_index: 0,
591-
});
592-
}
591+
})
592+
});
593593

594594
/// A registration of a thread with an index.
595595
///

0 commit comments

Comments
 (0)