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

Implement rwlocks on Windows #1461

Merged
merged 5 commits into from
Jun 28, 2020
Merged

Implement rwlocks on Windows #1461

merged 5 commits into from
Jun 28, 2020

Conversation

RalfJung
Copy link
Member

Fixes #1059

@RalfJung
Copy link
Member Author

@bors r+

@bors
Copy link
Contributor

bors commented Jun 28, 2020

📌 Commit 3a5bcb9 has been approved by RalfJung

@bors
Copy link
Contributor

bors commented Jun 28, 2020

⌛ Testing commit 3a5bcb9 with merge 1e9045b...

bors added a commit that referenced this pull request Jun 28, 2020
Implement rwlocks on Windows

Fixes #1059
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
#[allow(non_snake_case)]
fn AcquireSRWLockExclusive(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function could just invoke its Try* equivalent and cause the deadlock error in case the result is 0. That should help deduplicating the logic

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you looked at an old intermediate commit -- this changed quite a bit for the final PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I entirely re-implemented rwlocks later and figured I would keep the history. Sorry for the confusion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 I didn't get that far yet

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the thread id assertions are gone because the logic would now support threading? (I know we don't support thread starting yet at all, but the lock logic works now correctly for threads?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. It's the same logic as what we use on POSIX targets.

// Currently write locked. This is a deadlock.
throw_machine_stop!(TerminationInfo::Deadlock);
} else {
// Bump up read counter (cannot overflow as we just checkd against usize::MAX);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Bump up read counter (cannot overflow as we just checkd against usize::MAX);
// Bump up read counter (cannot overflow as we just checked against usize::MAX);

} else {
// Bump up read counter (cannot overflow as we just checkd against usize::MAX);
let new_val = lock_val+1;
// Make sure this does not reach the "write locked" flag.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice.

@RalfJung
Copy link
Member Author

@bors retry r-

@RalfJung
Copy link
Member Author

r? @oli-obk
sorry for self-r+'ing so quickly, I didn't know you were up for a review. :)

@bors
Copy link
Contributor

bors commented Jun 28, 2020

☀️ Try build successful - checks-travis, status-appveyor
Build commit: 1e9045b (1e9045b0c384ebb1401288e2d5bdb593c1b62db2)

if let Some(current_writer) = rwlock.writer {
if current_writer != expected_writer {
// Only the owner can unlock the rwlock.
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be an error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We leave error reporting to the caller. Mutexes do the same.

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with the review. This is pretty neat, especially how lots of the impl is deduplicated.

@RalfJung
Copy link
Member Author

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Jun 28, 2020

📌 Commit 3a5bcb9 has been approved by oli-obk

@bors
Copy link
Contributor

bors commented Jun 28, 2020

⌛ Testing commit 3a5bcb9 with merge 2dfa6c1...

@bors
Copy link
Contributor

bors commented Jun 28, 2020

☀️ Test successful - checks-travis, status-appveyor
Approved by: oli-obk
Pushing 2dfa6c1 to master...

@bors bors merged commit 2dfa6c1 into rust-lang:master Jun 28, 2020
@RalfJung RalfJung deleted the rwlock-win branch June 28, 2020 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for panics on Windows
3 participants