From 015031f6e7cc6c6d3984ec662934f95c732a2034 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Thu, 2 Sep 2021 13:40:26 -0500 Subject: [PATCH] refactor AccountEntry addref/unref --- runtime/src/accounts_index.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index 782944eaf1a37b..720ace4af95d71 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); } }