refactor AccountEntry addref/unref (#19583)

This commit is contained in:
Jeff Washington (jwash)
2021-09-02 18:25:27 -05:00
committed by GitHub
parent 682daf1117
commit 57f51352f6

View File

@ -114,9 +114,17 @@ pub struct AccountMapEntryInner<T> {
} }
impl<T> AccountMapEntryInner<T> { impl<T> AccountMapEntryInner<T> {
pub fn ref_count(&self) -> u64 { pub fn ref_count(&self) -> RefCount {
self.ref_count.load(Ordering::Relaxed) self.ref_count.load(Ordering::Relaxed)
} }
pub fn add_un_ref(&self, add: bool) {
if add {
self.ref_count.fetch_add(1, Ordering::Relaxed);
} else {
self.ref_count.fetch_sub(1, Ordering::Relaxed);
}
}
} }
pub enum AccountIndexGetResult<'a, T: IsCached> { pub enum AccountIndexGetResult<'a, T: IsCached> {
@ -153,19 +161,15 @@ impl<T: IsCached> ReadAccountMapEntry<T> {
} }
pub fn ref_count(&self) -> RefCount { pub fn ref_count(&self) -> RefCount {
self.borrow_owned_entry().ref_count.load(Ordering::Relaxed) self.borrow_owned_entry().ref_count()
} }
pub fn unref(&self) { pub fn unref(&self) {
self.borrow_owned_entry() self.borrow_owned_entry().add_un_ref(false);
.ref_count
.fetch_sub(1, Ordering::Relaxed);
} }
pub fn addref(&self) { pub fn addref(&self) {
self.borrow_owned_entry() self.borrow_owned_entry().add_un_ref(true);
.ref_count
.fetch_add(1, Ordering::Relaxed);
} }
} }
@ -213,10 +217,6 @@ impl<T: IsCached> WriteAccountMapEntry<T> {
}) })
} }
fn addref(item: &AtomicU64) {
item.fetch_add(1, Ordering::Relaxed);
}
pub fn upsert<'a>( pub fn upsert<'a>(
mut w_account_maps: AccountMapsWriteLock<'a, T>, mut w_account_maps: AccountMapsWriteLock<'a, T>,
pubkey: &Pubkey, pubkey: &Pubkey,
@ -278,7 +278,7 @@ impl<T: IsCached> WriteAccountMapEntry<T> {
previous_slot_entry_was_cached, previous_slot_entry_was_cached,
); );
if addref { if addref {
Self::addref(&current.ref_count); current.add_un_ref(true);
} }
} }