Skip to content

Commit

Permalink
Make jobserver initialization private in job_token mod
Browse files Browse the repository at this point in the history
  • Loading branch information
osiewicz committed Oct 2, 2023
1 parent 52afaf1 commit 3d45841
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/job_token.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use jobserver::{Acquired, Client, HelperThread};
use jobserver::{Acquired, HelperThread};
use std::{
env,
sync::{
Expand Down Expand Up @@ -47,7 +47,8 @@ pub(crate) struct JobTokenServer {
}

impl JobTokenServer {
pub(crate) fn new(client: Client) -> Result<Self, crate::Error> {
pub(crate) fn new() -> Result<Self, crate::Error> {
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.
Expand Down Expand Up @@ -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<jobserver::Client> = None;

Expand Down
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand 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();
Expand Down

0 comments on commit 3d45841

Please sign in to comment.