Use File::*lock*() in rustc_data_structures::flock when possible - #162584
Open
bjorn3 wants to merge 3 commits into
Open
Use File::*lock*() in rustc_data_structures::flock when possible#162584bjorn3 wants to merge 3 commits into
bjorn3 wants to merge 3 commits into
Conversation
Collaborator
|
r? @adwinwhite rustbot has assigned @adwinwhite. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Member
Author
|
cc @jackpot51 this enables |
bjorn3
force-pushed
the
incr_comp_prefer_flock
branch
from
September 10, 2026 11:36
df34325 to
67532d3
Compare
And only fallback to fcntl(F_SETLK) on Unix when flock() is not supported.
bjorn3
force-pushed
the
incr_comp_prefer_flock
branch
from
September 10, 2026 11:38
67532d3 to
2fe3696
Compare
bjorn3
commented
Sep 10, 2026
| impl Lock { | ||
| pub fn new(p: &Path, wait: bool, create: bool, exclusive: bool) -> io::Result<Lock> { | ||
| let mut open_options = OpenOptions::new(); | ||
| open_options.read(true).write(true).create(create); |
Member
Author
There was a problem hiding this comment.
On Windows .write(true) was only used when create is true. Seems harmless to me to always set it. On Windows .share_mode() was also used, but with a value matching the default, so I removed that one.
This comment was marked as spam.
This comment was marked as spam.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
And only fallback to
fcntl(F_SETLK)on Unix whenflock()is not supported.flock()is a lot more sane thanfcntl(F_SETLK)as it is fd scoped rather than process-scoped and reentrant.fcntl(F_SETLK)risks multiple instances of rustc inside the same process acquiring a lock on the same file even when an exclusive lock is requested. UsingFile::*lock*()also allows removing a fair amount of platform specific code for the file locking.Fixes #161361