Skip to content

Commit

Permalink
refactor AccountEntry addref/unref (solana-labs#19583)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored Sep 2, 2021
1 parent 682daf1 commit 57f5135
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions runtime/src/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,17 @@ pub struct AccountMapEntryInner<T> {
}

impl<T> AccountMapEntryInner<T> {
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> {
Expand Down Expand Up @@ -153,19 +161,15 @@ impl<T: IsCached> ReadAccountMapEntry<T> {
}

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

Expand Down Expand Up @@ -213,10 +217,6 @@ impl<T: IsCached> WriteAccountMapEntry<T> {
})
}

fn addref(item: &AtomicU64) {
item.fetch_add(1, Ordering::Relaxed);
}

pub fn upsert<'a>(
mut w_account_maps: AccountMapsWriteLock<'a, T>,
pubkey: &Pubkey,
Expand Down Expand Up @@ -278,7 +278,7 @@ impl<T: IsCached> WriteAccountMapEntry<T> {
previous_slot_entry_was_cached,
);
if addref {
Self::addref(&current.ref_count);
current.add_un_ref(true);
}
}

Expand Down

0 comments on commit 57f5135

Please sign in to comment.