Skip to content

Commit efd29db

Browse files
committed
Auto merge of #6748 - alexcrichton:release-then-acquire, r=ehuss
Release a jobserver token while locking a file This is a possible solution to #6747, but we'll ideally get some testing in before landing!
2 parents 2ed31b0 + 512fccb commit efd29db

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ hex = "0.3"
3939
home = "0.3"
4040
ignore = "0.4"
4141
lazy_static = "1.2.0"
42-
jobserver = "0.1.11"
42+
jobserver = "0.1.13"
4343
lazycell = "1.2.0"
4444
libc = "0.2"
4545
log = "0.4.6"

appveyor.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ environment:
22
matrix:
33
- TARGET: x86_64-pc-windows-msvc
44
OTHER_TARGET: i686-pc-windows-msvc
5-
- TARGET: x86_64-pc-windows-msvc
6-
MINIMAL_VERSIONS: true
7-
CFG_DISABLE_CROSS_TESTS: 1
85

96
install:
107
- if NOT defined APPVEYOR_PULL_REQUEST_NUMBER if "%APPVEYOR_REPO_BRANCH%" == "master" appveyor exit
118
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
129
- rustup-init.exe -y --default-host x86_64-pc-windows-msvc --default-toolchain nightly
1310
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
14-
- if defined MINIMAL_VERSIONS rustup toolchain install 1.31.0
1511
- if defined OTHER_TARGET rustup target add %OTHER_TARGET%
1612
- rustc -V
1713
- cargo -V
@@ -22,8 +18,4 @@ clone_depth: 1
2218
build: false
2319

2420
test_script:
25-
# we don't have ci time to run the full `cargo test` with `minimal-versions` like
26-
# - if defined MINIMAL_VERSIONS cargo +nightly generate-lockfile -Z minimal-versions && cargo +stable test
27-
# so we just run `cargo check --tests` like
28-
- if defined MINIMAL_VERSIONS cargo +nightly generate-lockfile -Z minimal-versions && cargo +1.31.0 check --tests --features=deny-warnings
29-
- if NOT defined MINIMAL_VERSIONS cargo test --features=deny-warnings
21+
- cargo test --features=deny-warnings

src/cargo/util/flock.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,27 @@ fn acquire(
312312
let msg = format!("waiting for file lock on {}", msg);
313313
config.shell().status_with_color("Blocking", &msg, Cyan)?;
314314

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?);
317336

318337
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
319338
fn is_on_nfs_mount(path: &Path) -> bool {

0 commit comments

Comments
 (0)