@@ -416,31 +416,34 @@ impl<'a, 'cfg> DrainState<'a, 'cfg> {
416
416
// Now that we've learned of all possible work that we can execute
417
417
// try to spawn it so long as we've got a jobserver token which says
418
418
// we're able to perform some parallel work.
419
- while self . active . len ( ) < self . tokens . len ( ) + 1 && !self . pending_queue . is_empty ( ) {
419
+ while self . has_extra_tokens ( ) && !self . pending_queue . is_empty ( ) {
420
420
let ( unit, job) = self . pending_queue . remove ( 0 ) ;
421
421
self . run ( & unit, job, cx, scope) ?;
422
422
}
423
423
424
424
Ok ( ( ) )
425
425
}
426
426
427
+ fn has_extra_tokens ( & self ) -> bool {
428
+ self . active . len ( ) < self . tokens . len ( ) + 1
429
+ }
430
+
431
+ // If we managed to acquire some extra tokens, send them off to a waiting rustc.
427
432
fn grant_rustc_token_requests ( & mut self ) -> CargoResult < ( ) > {
428
- // If we managed to acquire some extra tokens, send them off to a waiting rustc.
429
- let extra_tokens = self . tokens . len ( ) - ( self . active . len ( ) - 1 ) ;
430
- for _ in 0 ..extra_tokens {
431
- if !self . to_send_clients . is_empty ( ) {
432
- // remove from the front so we grant the token to the oldest
433
- // waiter
434
- let ( id, client) = self . to_send_clients . remove ( 0 ) ;
435
- let token = self . tokens . pop ( ) . expect ( "an extra token" ) ;
436
- self . rustc_tokens
437
- . entry ( id)
438
- . or_insert_with ( Vec :: new)
439
- . push ( token) ;
440
- client
441
- . release_raw ( )
442
- . chain_err ( || "failed to release jobserver token" ) ?;
443
- }
433
+ while !self . to_send_clients . is_empty ( ) && self . has_extra_tokens ( ) {
434
+ // Remove from the front so we grant the token to the oldest waiter
435
+ let ( id, client) = self . to_send_clients . remove ( 0 ) ;
436
+ // This unwrap is guaranteed to succeed. `active` must be at least
437
+ // length 1, as otherwise there can't be a client waiting to be sent
438
+ // on, so tokens.len() must also be at least one.
439
+ let token = self . tokens . pop ( ) . unwrap ( ) ;
440
+ self . rustc_tokens
441
+ . entry ( id)
442
+ . or_insert_with ( Vec :: new)
443
+ . push ( token) ;
444
+ client
445
+ . release_raw ( )
446
+ . chain_err ( || "failed to release jobserver token" ) ?;
444
447
}
445
448
446
449
Ok ( ( ) )
0 commit comments