Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release a jobserver token while locking a file #6748

Merged
merged 2 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ hex = "0.3"
home = "0.3"
ignore = "0.4"
lazy_static = "1.2.0"
jobserver = "0.1.11"
jobserver = "0.1.13"
lazycell = "1.2.0"
libc = "0.2"
log = "0.4.6"
Expand Down
10 changes: 1 addition & 9 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ environment:
matrix:
- TARGET: x86_64-pc-windows-msvc
OTHER_TARGET: i686-pc-windows-msvc
- TARGET: x86_64-pc-windows-msvc
MINIMAL_VERSIONS: true
CFG_DISABLE_CROSS_TESTS: 1

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

test_script:
# we don't have ci time to run the full `cargo test` with `minimal-versions` like
# - if defined MINIMAL_VERSIONS cargo +nightly generate-lockfile -Z minimal-versions && cargo +stable test
# so we just run `cargo check --tests` like
- if defined MINIMAL_VERSIONS cargo +nightly generate-lockfile -Z minimal-versions && cargo +1.31.0 check --tests --features=deny-warnings
- if NOT defined MINIMAL_VERSIONS cargo test --features=deny-warnings
- cargo test --features=deny-warnings
23 changes: 21 additions & 2 deletions src/cargo/util/flock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,27 @@ fn acquire(
let msg = format!("waiting for file lock on {}", msg);
config.shell().status_with_color("Blocking", &msg, Cyan)?;

block().chain_err(|| format!("failed to lock file: {}", path.display()))?;
return Ok(());
// We're about to block the current process and not really do anything
// productive for what could possibly be a very long time. We could be
// waiting, for example, on another Cargo to finish a download, finish an
// entire build, etc. Since we're not doing anything productive we're not
// making good use of our jobserver token, if we have one.
//
// This can typically come about if `cargo` is invoked from `make` (or some
// other jobserver-providing system). In this situation it's actually best
// if we release the token back to the original jobserver to let some other
// cpu-hungry work continue to make progress. After we're done blocking
// we'll block waiting to reacquire a token as we'll probably be doing cpu
// hungry work ourselves.
let jobserver = config.jobserver_from_env();
if let Some(server) = jobserver {
server.release_raw()?;
}
let result = block().chain_err(|| format!("failed to lock file: {}", path.display()));
if let Some(server) = jobserver {
server.acquire_raw()?;
}
return Ok(result?);

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