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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 9 deletions

View File

@ -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 {
@ -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);
}