@@ -943,6 +943,14 @@ impl Build {
943
943
use std:: sync:: atomic:: { AtomicBool , Ordering :: SeqCst } ;
944
944
use std:: sync:: Once ;
945
945
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
+
946
954
// When compiling objects in parallel we do a few dirty tricks to speed
947
955
// things up:
948
956
//
@@ -976,8 +984,6 @@ impl Build {
976
984
// Note that as a slight optimization we try to break out as soon as
977
985
// possible as soon as any compilation fails to ensure that errors get
978
986
// 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
981
987
let error = AtomicBool :: new ( false ) ;
982
988
let mut threads = Vec :: new ( ) ;
983
989
for obj in objs {
@@ -1011,7 +1017,9 @@ impl Build {
1011
1017
1012
1018
// Reacquire our process's token before we proceed, which we released
1013
1019
// before entering the loop above.
1014
- server. acquire_raw ( ) ?;
1020
+ if reacquire {
1021
+ server. acquire_raw ( ) ?;
1022
+ }
1015
1023
1016
1024
return Ok ( ( ) ) ;
1017
1025
0 commit comments