Skip to content

Commit

Permalink
renames
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Aug 4, 2023
1 parent 5aa42d2 commit 02d0e92
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions runtime/src/read_only_accounts_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ struct ReadOnlyAccountCacheEntry {
account: AccountSharedData,
/// Index of the entry in the eviction queue.
index: Index,
/// lower bits of last timestamp when eviction queue was updated
last_time: u32,
/// lower bits of last timestamp when eviction queue was updated, in ms
last_update_time: u32,
}

impl ReadOnlyAccountCacheEntry {
fn new(account: AccountSharedData, index: Index) -> Self {
Self {
account,
index,
last_time: Self::timestamp(),
last_update_time: Self::timestamp(),
}
}
/// lower bits of current timestamp. We don't need higher bits and u32 packs with Index u32 in `ReadOnlyAccountCacheEntry`
fn timestamp() -> u32 {
timestamp() as u32
}
/// ms since `last_time` timestamp
fn ms_since_last_time(&self) -> u32 {
Self::timestamp().wrapping_sub(self.last_time)
/// ms since `last_update_time` timestamp
fn ms_since_last_update(&self) -> u32 {
Self::timestamp().wrapping_sub(self.last_update_time)
}
}

Expand Down Expand Up @@ -112,12 +112,12 @@ impl ReadOnlyAccountsCache {
// self.queue is modified while holding a reference to the cache entry;
// so that another thread cannot write to the same key.
// If we updated the eviction queue within this much time, then leave it where it is. We're likely to hit it again.
let update_lru = entry.ms_since_last_time() >= self.ms_to_skip_lru_update;
let update_lru = entry.ms_since_last_update() >= self.ms_to_skip_lru_update;
if update_lru {
let mut queue = self.queue.lock().unwrap();
queue.remove(entry.index);
entry.index = queue.insert_last(key);
entry.last_time = ReadOnlyAccountCacheEntry::timestamp();
entry.last_update_time = ReadOnlyAccountCacheEntry::timestamp();
}
let account = entry.account.clone();
drop(entry);
Expand Down

0 comments on commit 02d0e92

Please sign in to comment.