fix memory ordering in append_vec (#23215)

This commit is contained in:
HaoranYi 2022-02-20 20:30:49 -06:00 committed by GitHub
parent 42bdf1d864
commit 04d23a1597
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -286,11 +286,11 @@ impl AppendVec {
// This mutex forces append to be single threaded, but concurrent with reads // This mutex forces append to be single threaded, but concurrent with reads
// See UNSAFE usage in `append_ptr` // See UNSAFE usage in `append_ptr`
let _lock = self.append_lock.lock().unwrap(); let _lock = self.append_lock.lock().unwrap();
self.current_len.store(0, Ordering::Relaxed); self.current_len.store(0, Ordering::Release);
} }
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.current_len.load(Ordering::Relaxed) self.current_len.load(Ordering::Acquire)
} }
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
@ -360,7 +360,7 @@ impl AppendVec {
offset = next_offset; offset = next_offset;
num_accounts += 1; num_accounts += 1;
} }
let aligned_current_len = u64_align!(self.current_len.load(Ordering::Relaxed)); let aligned_current_len = u64_align!(self.current_len.load(Ordering::Acquire));
(offset == aligned_current_len, num_accounts) (offset == aligned_current_len, num_accounts)
} }
@ -419,7 +419,7 @@ impl AppendVec {
for val in vals { for val in vals {
self.append_ptr(offset, val.0, val.1) self.append_ptr(offset, val.0, val.1)
} }
self.current_len.store(*offset, Ordering::Relaxed); self.current_len.store(*offset, Ordering::Release);
Some(pos) Some(pos)
} }