diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index 3393d3640add05..2c18b49881a23f 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -114,9 +114,17 @@ pub struct AccountMapEntryInner { } impl AccountMapEntryInner { - pub fn ref_count(&self) -> u64 { + pub fn ref_count(&self) -> RefCount { 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> { @@ -153,19 +161,15 @@ impl ReadAccountMapEntry { } 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) { - self.borrow_owned_entry() - .ref_count - .fetch_sub(1, Ordering::Relaxed); + self.borrow_owned_entry().add_un_ref(false); } pub fn addref(&self) { - self.borrow_owned_entry() - .ref_count - .fetch_add(1, Ordering::Relaxed); + self.borrow_owned_entry().add_un_ref(true); } } @@ -213,10 +217,6 @@ impl WriteAccountMapEntry { }) } - fn addref(item: &AtomicU64) { - item.fetch_add(1, Ordering::Relaxed); - } - pub fn upsert<'a>( mut w_account_maps: AccountMapsWriteLock<'a, T>, pubkey: &Pubkey, @@ -278,7 +278,7 @@ impl WriteAccountMapEntry { previous_slot_entry_was_cached, ); if addref { - Self::addref(¤t.ref_count); + current.add_un_ref(true); } }