Skip to content

Commit 3bf2c62

Browse files
committed
More jobserver rejiggering
1 parent d246b6a commit 3bf2c62

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,14 @@ impl Build {
943943
use std::sync::atomic::{AtomicBool, Ordering::SeqCst};
944944
use std::sync::Once;
945945

946+
// Limit our parallelism globally with a jobserver. Start off by
947+
// releasing our own token for this process so we can have a bit of an
948+
// easier to write loop below. If this fails, though, then we're likely
949+
// on Windows with the main implicit token, so we just have a bit extra
950+
// parallelism for a bit and don't reacquire later.
951+
let server = jobserver();
952+
let reacquire = server.release_raw().is_ok();
953+
946954
// When compiling objects in parallel we do a few dirty tricks to speed
947955
// things up:
948956
//
@@ -976,8 +984,6 @@ impl Build {
976984
// Note that as a slight optimization we try to break out as soon as
977985
// possible as soon as any compilation fails to ensure that errors get
978986
// out to the user as fast as possible.
979-
let server = jobserver();
980-
server.release_raw()?; // release our process's token which we'll reacquire in the loop
981987
let error = AtomicBool::new(false);
982988
let mut threads = Vec::new();
983989
for obj in objs {
@@ -1011,7 +1017,9 @@ impl Build {
10111017

10121018
// Reacquire our process's token before we proceed, which we released
10131019
// before entering the loop above.
1014-
server.acquire_raw()?;
1020+
if reacquire {
1021+
server.acquire_raw()?;
1022+
}
10151023

10161024
return Ok(());
10171025

0 commit comments

Comments
 (0)