Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Disk Buckets: unlock verifies expected (#22052)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored Dec 21, 2021
1 parent 9c5d825 commit 5b464a3
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions bucket_map/src/bucket_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ impl Header {
false
}
}
fn unlock(&mut self) -> Uid {
let old = self.lock;
fn unlock(&mut self, expected: Uid) {
assert_eq!(expected, self.lock);
self.lock = UID_UNLOCKED;
old
}
fn uid(&self) -> Option<Uid> {
if self.lock == UID_UNLOCKED {
Expand Down Expand Up @@ -188,12 +187,7 @@ impl BucketStorage {
pub fn free(&mut self, ix: u64, uid: Uid) {
assert!(ix < self.capacity(), "bad index size");
assert!(UID_UNLOCKED != uid, "free: bad uid");
let previous_uid = self.header_mut_ptr(ix).unlock();
assert_eq!(
previous_uid, uid,
"free: unlocked a header with a differet uid: {}",
previous_uid
);
self.header_mut_ptr(ix).unlock(uid);
self.count.fetch_sub(1, Ordering::Relaxed);
}

Expand Down

0 comments on commit 5b464a3

Please sign in to comment.