datastructures: replace lazy_static
by SyncLazy
from std
This commit is contained in:
parent
bd49eec3d7
commit
1b650d0fea
@ -3417,7 +3417,6 @@ dependencies = [
|
|||||||
"ena",
|
"ena",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"jobserver",
|
"jobserver",
|
||||||
"lazy_static",
|
|
||||||
"libc",
|
"libc",
|
||||||
"measureme",
|
"measureme",
|
||||||
"parking_lot 0.10.2",
|
"parking_lot 0.10.2",
|
||||||
|
@ -12,7 +12,6 @@ ena = "0.14"
|
|||||||
indexmap = "1.5.1"
|
indexmap = "1.5.1"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
jobserver_crate = { version = "0.1.13", package = "jobserver" }
|
jobserver_crate = { version = "0.1.13", package = "jobserver" }
|
||||||
lazy_static = "1"
|
|
||||||
rustc_serialize = { path = "../rustc_serialize" }
|
rustc_serialize = { path = "../rustc_serialize" }
|
||||||
rustc_macros = { path = "../rustc_macros" }
|
rustc_macros = { path = "../rustc_macros" }
|
||||||
rustc_graphviz = { path = "../rustc_graphviz" }
|
rustc_graphviz = { path = "../rustc_graphviz" }
|
||||||
|
@ -1,33 +1,31 @@
|
|||||||
pub use jobserver_crate::Client;
|
pub use jobserver_crate::Client;
|
||||||
use lazy_static::lazy_static;
|
use std::lazy::SyncLazy;
|
||||||
|
|
||||||
lazy_static! {
|
// We can only call `from_env` once per process
|
||||||
// We can only call `from_env` once per process
|
|
||||||
|
|
||||||
// Note that this is unsafe because it may misinterpret file descriptors
|
// Note that this is unsafe because it may misinterpret file descriptors
|
||||||
// on Unix as jobserver file descriptors. We hopefully execute this near
|
// on Unix as jobserver file descriptors. We hopefully execute this near
|
||||||
// the beginning of the process though to ensure we don't get false
|
// the beginning of the process though to ensure we don't get false
|
||||||
// positives, or in other words we try to execute this before we open
|
// positives, or in other words we try to execute this before we open
|
||||||
// any file descriptors ourselves.
|
// any file descriptors ourselves.
|
||||||
//
|
//
|
||||||
// Pick a "reasonable maximum" if we don't otherwise have
|
// Pick a "reasonable maximum" if we don't otherwise have
|
||||||
// a jobserver in our environment, capping out at 32 so we
|
// a jobserver in our environment, capping out at 32 so we
|
||||||
// don't take everything down by hogging the process run queue.
|
// don't take everything down by hogging the process run queue.
|
||||||
// The fixed number is used to have deterministic compilation
|
// The fixed number is used to have deterministic compilation
|
||||||
// across machines.
|
// across machines.
|
||||||
//
|
//
|
||||||
// Also note that we stick this in a global because there could be
|
// Also note that we stick this in a global because there could be
|
||||||
// multiple rustc instances in this process, and the jobserver is
|
// multiple rustc instances in this process, and the jobserver is
|
||||||
// per-process.
|
// per-process.
|
||||||
static ref GLOBAL_CLIENT: Client = unsafe {
|
static GLOBAL_CLIENT: SyncLazy<Client> = SyncLazy::new(|| unsafe {
|
||||||
Client::from_env().unwrap_or_else(|| {
|
Client::from_env().unwrap_or_else(|| {
|
||||||
let client = Client::new(32).expect("failed to create jobserver");
|
let client = Client::new(32).expect("failed to create jobserver");
|
||||||
// Acquire a token for the main thread which we can release later
|
// Acquire a token for the main thread which we can release later
|
||||||
client.acquire_raw().ok();
|
client.acquire_raw().ok();
|
||||||
client
|
client
|
||||||
})
|
})
|
||||||
};
|
});
|
||||||
}
|
|
||||||
|
|
||||||
pub fn client() -> Client {
|
pub fn client() -> Client {
|
||||||
GLOBAL_CLIENT.clone()
|
GLOBAL_CLIENT.clone()
|
||||||
|
Loading…
Reference in New Issue
Block a user