diff --git a/src/job_token.rs b/src/job_token.rs index c485f8b..97867e5 100644 --- a/src/job_token.rs +++ b/src/job_token.rs @@ -1,4 +1,4 @@ -use jobserver::{Acquired, Client, HelperThread}; +use jobserver::{Acquired, Client}; use std::{ env, sync::{ @@ -41,7 +41,7 @@ impl JobToken { /// Furthermore, instead of giving up job tokens, it keeps them around /// for reuse if we know we're going to request another token after freeing the current one. pub(crate) struct JobTokenServer { - helper: HelperThread, + client: Client, tx: Sender>, rx: Receiver>, } @@ -52,26 +52,21 @@ impl JobTokenServer { // Push the implicit token. Since JobTokens only give back what they got, // there should be at most one global implicit token in the wild. tx.send(None).unwrap(); - let pool = tx.clone(); - let helper = client.into_helper_thread(move |acq| { - let _ = pool.send(Some(acq.unwrap())); - })?; - Ok(Self { helper, tx, rx }) + Ok(Self { client, tx, rx }) } - pub(crate) fn acquire(&mut self) -> JobToken { + pub(crate) fn acquire(&mut self) -> Result { let token = if let Ok(token) = self.rx.try_recv() { // Opportunistically check if there's a token that can be reused. token } else { // Cold path, request a token and block - self.helper.request_token(); - self.rx.recv().unwrap() + Some(self.client.acquire()?) }; - JobToken { + Ok(JobToken { token, pool: Some(self.tx.clone()), - } + }) } } diff --git a/src/lib.rs b/src/lib.rs index 4be1367..b4e40e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1429,7 +1429,7 @@ 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(); + let token = tokens.acquire()?; let child = spawn(&mut cmd, &program, print.pipe_writer_cloned()?.unwrap())?; tx.send((cmd, program, KillOnDrop(child), token))