refactor AccountEntry addref/unref (#19583)
This commit is contained in:
parent
682daf1117
commit
57f51352f6
@ -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> {
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,
|
||||
@ -278,7 +278,7 @@ impl<T: IsCached> WriteAccountMapEntry<T> {
|
||||
previous_slot_entry_was_cached,
|
||||
);
|
||||
if addref {
|
||||
Self::addref(¤t.ref_count);
|
||||
current.add_un_ref(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user