Skip to content

Commit

Permalink
Always inline should_update and should_update_ext (anza-xyz#3228)
Browse files Browse the repository at this point in the history
This function is used in many places
  • Loading branch information
ksolana authored Oct 24, 2024
1 parent 415a78a commit d6c7fd0
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sdk/src/timing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ pub struct AtomicInterval {

impl AtomicInterval {
/// true if 'interval_time_ms' has elapsed since last time we returned true as long as it has been 'interval_time_ms' since this struct was created
#[inline(always)]
pub fn should_update(&self, interval_time_ms: u64) -> bool {
self.should_update_ext(interval_time_ms, true)
}

/// a primary use case is periodic metric reporting, potentially from different threads
/// true if 'interval_time_ms' has elapsed since last time we returned true
/// except, if skip_first=false, false until 'interval_time_ms' has elapsed since this struct was created
#[inline(always)]
pub fn should_update_ext(&self, interval_time_ms: u64, skip_first: bool) -> bool {
let now = timestamp();
let last = self.last_update.load(Ordering::Relaxed);
Expand Down

0 comments on commit d6c7fd0

Please sign in to comment.