@@ -312,8 +312,27 @@ fn acquire(
312
312
let msg = format ! ( "waiting for file lock on {}" , msg) ;
313
313
config. shell ( ) . status_with_color ( "Blocking" , & msg, Cyan ) ?;
314
314
315
- block ( ) . chain_err ( || format ! ( "failed to lock file: {}" , path. display( ) ) ) ?;
316
- return Ok ( ( ) ) ;
315
+ // We're about to block the current process and not really do anything
316
+ // productive for what could possibly be a very long time. We could be
317
+ // waiting, for example, on another Cargo to finish a download, finish an
318
+ // entire build, etc. Since we're not doing anything productive we're not
319
+ // making good use of our jobserver token, if we have one.
320
+ //
321
+ // This can typically come about if `cargo` is invoked from `make` (or some
322
+ // other jobserver-providing system). In this situation it's actually best
323
+ // if we release the token back to the original jobserver to let some other
324
+ // cpu-hungry work continue to make progress. After we're done blocking
325
+ // we'll block waiting to reacquire a token as we'll probably be doing cpu
326
+ // hungry work ourselves.
327
+ let jobserver = config. jobserver_from_env ( ) ;
328
+ if let Some ( server) = jobserver {
329
+ server. release_raw ( ) ?;
330
+ }
331
+ let result = block ( ) . chain_err ( || format ! ( "failed to lock file: {}" , path. display( ) ) ) ;
332
+ if let Some ( server) = jobserver {
333
+ server. acquire_raw ( ) ?;
334
+ }
335
+ return Ok ( result?) ;
317
336
318
337
#[ cfg( all( target_os = "linux" , not( target_env = "musl" ) ) ) ]
319
338
fn is_on_nfs_mount ( path : & Path ) -> bool {
0 commit comments