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
[core] Ensure all lock guards are properly nested. #5646
Conversation
Rather than implementing `Drop` for all three lock guard types to restore the lock analysis' per-thread state, let lock guards own values of a new type, `LockStateGuard`, with the appropriate `Drop` implementation. This is cleaner and shorter, and helps us implement `RwLock::downgrade` in a later commit.
Implement `RwLockWriteGuard::downgrade` for `lock::vanilla` and `lock::ranked`, to downgrade a write lock to a read lock.
The lock analyzers in the `wgpu_core::lock` module can be a bit simpler if they can assume that locks are acquired and released in a stack-like order: that a guard is only dropped when it is the most recently acquired lock guard still held. So: - Change `Device::maintain` to take a `RwLockReadGuard` for the device's hal fence, rather than just a reference to it. - Adjust the order in which guards are dropped in `Device::maintain` and `Queue::submit`. Fixes gfx-rs#5610.
The interesting thing for reviewers to consider here is the shifting of the code that assigns to |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shippit
The lock analyzers in the
wgpu_core::lock
module can be a bitsimpler if they can assume that locks are acquired and released in a
stack-like order: that a guard is only dropped when it is the most
recently acquired lock guard still held. So:
Change
Device::maintain
to take aRwLockReadGuard
for the device's hal fence, rather than just a reference to it.Adjust the order in which guards are dropped in
Device::maintain
andQueue::submit
.Implement
downgrade
for thelock
module'sRwLock
s.Implement
RwLockWriteGuard::downgrade
forlock::vanilla
andlock::ranked
, to downgrade a write lock to a read lock.Refactor
lock::ranked
to useLockStateGuard
.Rather than implementing
Drop
for all three lock guard types to restore the lock analysis' per-thread state, let lock guards own values of a new type,LockStateGuard
, with the appropriateDrop
implementation. This is cleaner and shorter, and helps us implementRwLock::downgrade
in a later commit.Fixes #5610.