From 3d458416426402d403b1ff41d61b53625cfc39f8 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:28:03 +0200 Subject: [PATCH] Make jobserver initialization private in job_token mod --- src/job_token.rs | 7 ++++--- src/lib.rs | 4 +--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/job_token.rs b/src/job_token.rs index c485f8be..f5e69b8f 100644 --- a/src/job_token.rs +++ b/src/job_token.rs @@ -1,4 +1,4 @@ -use jobserver::{Acquired, Client, HelperThread}; +use jobserver::{Acquired, HelperThread}; use std::{ env, sync::{ @@ -47,7 +47,8 @@ pub(crate) struct JobTokenServer { } impl JobTokenServer { - pub(crate) fn new(client: Client) -> Result { + pub(crate) fn new() -> Result { + let client = jobserver(); let (tx, rx) = mpsc::channel(); // Push the implicit token. Since JobTokens only give back what they got, // there should be at most one global implicit token in the wild. @@ -77,7 +78,7 @@ impl JobTokenServer { /// Returns a suitable `jobserver::Client` used to coordinate /// parallelism between build scripts. -pub(super) fn jobserver() -> jobserver::Client { +fn jobserver() -> jobserver::Client { static INIT: Once = Once::new(); static mut JOBSERVER: Option = None; diff --git a/src/lib.rs b/src/lib.rs index 4be13675..d3ed7dc8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1306,8 +1306,7 @@ impl Build { } // Limit our parallelism globally with a jobserver. - let server = job_token::jobserver(); - // Reacquire our process's token on drop + let mut tokens = crate::job_token::JobTokenServer::new()?; // When compiling objects in parallel we do a few dirty tricks to speed // things up: @@ -1426,7 +1425,6 @@ impl Build { }; } })?; - let mut tokens = crate::job_token::JobTokenServer::new(server)?; for obj in objs { let (mut cmd, program) = self.create_compile_object_cmd(obj)?; let token = tokens.acquire();