Disk Buckets: unlock verifies expected (#22052)

This commit is contained in:
Jeff Washington (jwash)
2021-12-21 16:35:59 -06:00
committed by GitHub
parent 9c5d82557a
commit 5b464a32f5

View File

@ -53,10 +53,9 @@ impl Header {
false false
} }
} }
fn unlock(&mut self) -> Uid { fn unlock(&mut self, expected: Uid) {
let old = self.lock; assert_eq!(expected, self.lock);
self.lock = UID_UNLOCKED; self.lock = UID_UNLOCKED;
old
} }
fn uid(&self) -> Option<Uid> { fn uid(&self) -> Option<Uid> {
if self.lock == UID_UNLOCKED { if self.lock == UID_UNLOCKED {
@ -188,12 +187,7 @@ impl BucketStorage {
pub fn free(&mut self, ix: u64, uid: Uid) { pub fn free(&mut self, ix: u64, uid: Uid) {
assert!(ix < self.capacity(), "bad index size"); assert!(ix < self.capacity(), "bad index size");
assert!(UID_UNLOCKED != uid, "free: bad uid"); assert!(UID_UNLOCKED != uid, "free: bad uid");
let previous_uid = self.header_mut_ptr(ix).unlock(); self.header_mut_ptr(ix).unlock(uid);
assert_eq!(
previous_uid, uid,
"free: unlocked a header with a differet uid: {}",
previous_uid
);
self.count.fetch_sub(1, Ordering::Relaxed); self.count.fetch_sub(1, Ordering::Relaxed);
} }