Skip to content

Commit

Permalink
Merge pull request #393 from Amanieu/fix-with_upgraded
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Jun 30, 2023
2 parents d36110f + 64b7114 commit 5d3d18f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lock_api/src/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,7 @@ impl<'a, R: RawRwLockUpgradeDowngrade + 'a, T: ?Sized + 'a> RwLockUpgradableRead

// Safety: We just upgraded the lock, so we have mutable access to the data.
// This will restore the state the lock was in at the start of the function.
defer!(unsafe { self.rwlock.raw.downgrade_upgradable() });
defer!(unsafe { self.rwlock.raw.downgrade_to_upgradable() });

// Safety: We upgraded the lock, so we have mutable access to the data.
// When this function returns, whether by drop or panic,
Expand All @@ -2047,7 +2047,7 @@ impl<'a, R: RawRwLockUpgradeDowngrade + 'a, T: ?Sized + 'a> RwLockUpgradableRead
if unsafe { self.rwlock.raw.try_upgrade() } {
// Safety: We just upgraded the lock, so we have mutable access to the data.
// This will restore the state the lock was in at the start of the function.
defer!(unsafe { self.rwlock.raw.downgrade_upgradable() });
defer!(unsafe { self.rwlock.raw.downgrade_to_upgradable() });

// Safety: We upgraded the lock, so we have mutable access to the data.
// When this function returns, whether by drop or panic,
Expand Down
15 changes: 15 additions & 0 deletions tests/issue_392.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use parking_lot::RwLock;

struct Lock(RwLock<i32>);

#[test]
fn issue_392() {
let lock = Lock(RwLock::new(0));
let mut rl = lock.0.upgradable_read();
rl.with_upgraded(|_| {
println!("lock upgrade");
});
rl.with_upgraded(|_| {
println!("lock upgrade");
});
}

0 comments on commit 5d3d18f

Please sign in to comment.