diff options
| author | marmeladema <xademax@gmail.com> | 2020-08-30 11:48:50 +0100 |
|---|---|---|
| committer | marmeladema <xademax@gmail.com> | 2020-09-01 22:06:47 +0100 |
| commit | 1b650d0fea209e0b69407a0a1e04feeb57c4b2d4 (patch) | |
| tree | 4947a3c442a8c95d461111137fe0e9073bc14000 /compiler/rustc_data_structures/src/jobserver.rs | |
| parent | bd49eec3d76d5894b539a28309c2fe24f915ee94 (diff) | |
| download | rust-1b650d0fea209e0b69407a0a1e04feeb57c4b2d4.tar.gz rust-1b650d0fea209e0b69407a0a1e04feeb57c4b2d4.zip | |
datastructures: replace `lazy_static` by `SyncLazy` from std
Diffstat (limited to 'compiler/rustc_data_structures/src/jobserver.rs')
| -rw-r--r-- | compiler/rustc_data_structures/src/jobserver.rs | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/compiler/rustc_data_structures/src/jobserver.rs b/compiler/rustc_data_structures/src/jobserver.rs index a811c88839d..41605afb44e 100644 --- a/compiler/rustc_data_structures/src/jobserver.rs +++ b/compiler/rustc_data_structures/src/jobserver.rs @@ -1,33 +1,31 @@ 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 - // on Unix as jobserver file descriptors. We hopefully execute this near - // 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 - // any file descriptors ourselves. - // - // Pick a "reasonable maximum" if we don't otherwise have - // a jobserver in our environment, capping out at 32 so we - // don't take everything down by hogging the process run queue. - // The fixed number is used to have deterministic compilation - // across machines. - // - // Also note that we stick this in a global because there could be - // multiple rustc instances in this process, and the jobserver is - // per-process. - static ref GLOBAL_CLIENT: Client = unsafe { - Client::from_env().unwrap_or_else(|| { - let client = Client::new(32).expect("failed to create jobserver"); - // Acquire a token for the main thread which we can release later - client.acquire_raw().ok(); - client - }) - }; -} +// Note that this is unsafe because it may misinterpret file descriptors +// on Unix as jobserver file descriptors. We hopefully execute this near +// 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 +// any file descriptors ourselves. +// +// Pick a "reasonable maximum" if we don't otherwise have +// a jobserver in our environment, capping out at 32 so we +// don't take everything down by hogging the process run queue. +// The fixed number is used to have deterministic compilation +// across machines. +// +// Also note that we stick this in a global because there could be +// multiple rustc instances in this process, and the jobserver is +// per-process. +static GLOBAL_CLIENT: SyncLazy<Client> = SyncLazy::new(|| unsafe { + Client::from_env().unwrap_or_else(|| { + let client = Client::new(32).expect("failed to create jobserver"); + // Acquire a token for the main thread which we can release later + client.acquire_raw().ok(); + client + }) +}); pub fn client() -> Client { GLOBAL_CLIENT.clone() |
