Skip to content

Commit 1b650d0

Browse files
committed
datastructures: replace lazy_static by SyncLazy from std
1 parent bd49eec commit 1b650d0

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -3417,7 +3417,6 @@ dependencies = [
34173417
"ena",
34183418
"indexmap",
34193419
"jobserver",
3420-
"lazy_static",
34213420
"libc",
34223421
"measureme",
34233422
"parking_lot 0.10.2",

compiler/rustc_data_structures/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ ena = "0.14"
1212
indexmap = "1.5.1"
1313
tracing = "0.1"
1414
jobserver_crate = { version = "0.1.13", package = "jobserver" }
15-
lazy_static = "1"
1615
rustc_serialize = { path = "../rustc_serialize" }
1716
rustc_macros = { path = "../rustc_macros" }
1817
rustc_graphviz = { path = "../rustc_graphviz" }

compiler/rustc_data_structures/src/jobserver.rs

+25-27
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
11
pub use jobserver_crate::Client;
2-
use lazy_static::lazy_static;
2+
use std::lazy::SyncLazy;
33

4-
lazy_static! {
5-
// We can only call `from_env` once per process
4+
// We can only call `from_env` once per process
65

7-
// Note that this is unsafe because it may misinterpret file descriptors
8-
// on Unix as jobserver file descriptors. We hopefully execute this near
9-
// the beginning of the process though to ensure we don't get false
10-
// positives, or in other words we try to execute this before we open
11-
// any file descriptors ourselves.
12-
//
13-
// Pick a "reasonable maximum" if we don't otherwise have
14-
// a jobserver in our environment, capping out at 32 so we
15-
// don't take everything down by hogging the process run queue.
16-
// The fixed number is used to have deterministic compilation
17-
// across machines.
18-
//
19-
// Also note that we stick this in a global because there could be
20-
// multiple rustc instances in this process, and the jobserver is
21-
// per-process.
22-
static ref GLOBAL_CLIENT: Client = unsafe {
23-
Client::from_env().unwrap_or_else(|| {
24-
let client = Client::new(32).expect("failed to create jobserver");
25-
// Acquire a token for the main thread which we can release later
26-
client.acquire_raw().ok();
27-
client
28-
})
29-
};
30-
}
6+
// Note that this is unsafe because it may misinterpret file descriptors
7+
// on Unix as jobserver file descriptors. We hopefully execute this near
8+
// the beginning of the process though to ensure we don't get false
9+
// positives, or in other words we try to execute this before we open
10+
// any file descriptors ourselves.
11+
//
12+
// Pick a "reasonable maximum" if we don't otherwise have
13+
// a jobserver in our environment, capping out at 32 so we
14+
// don't take everything down by hogging the process run queue.
15+
// The fixed number is used to have deterministic compilation
16+
// across machines.
17+
//
18+
// Also note that we stick this in a global because there could be
19+
// multiple rustc instances in this process, and the jobserver is
20+
// per-process.
21+
static GLOBAL_CLIENT: SyncLazy<Client> = SyncLazy::new(|| unsafe {
22+
Client::from_env().unwrap_or_else(|| {
23+
let client = Client::new(32).expect("failed to create jobserver");
24+
// Acquire a token for the main thread which we can release later
25+
client.acquire_raw().ok();
26+
client
27+
})
28+
});
3129

3230
pub fn client() -> Client {
3331
GLOBAL_CLIENT.clone()

0 commit comments

Comments
 (0)