pub struct GlobalTimer {
pub base_timestamp: i64,
pub base_instant: Instant,
pub last_sync_at: Instant,
}Expand description
Core data structure for global timer management
Fields§
§base_timestamp: i64Initial timestamp fetched from NTP
base_instant: InstantReference point of system clock
last_sync_at: InstantTimestamp of last NTP synchronization
Implementations§
Source§impl GlobalTimer
impl GlobalTimer
Sourcepub fn new(initial_timestamp: i64) -> Self
pub fn new(initial_timestamp: i64) -> Self
Creates a new global timer with the given NTP timestamp
Sourcepub fn get_current_timestamp(&self) -> i64
pub fn get_current_timestamp(&self) -> i64
Gets the current timestamp via fast local calculation
Sourcepub fn detect_clock_jump(&self, new_ntp_timestamp: i64, threshold: i64) -> bool
pub fn detect_clock_jump(&self, new_ntp_timestamp: i64, threshold: i64) -> bool
Detects if a clock jump occurred by comparing NTP timestamp with internal estimate
Sourcepub fn update_timestamp(&mut self, new_timestamp: i64, is_jump: bool)
pub fn update_timestamp(&mut self, new_timestamp: i64, is_jump: bool)
更新时间戳(处理时钟跳跃或漂移纠正)
Sourcepub fn should_sync(&self, sync_interval: u64) -> bool
pub fn should_sync(&self, sync_interval: u64) -> bool
检查是否需要进行同步
Trait Implementations§
Source§impl Clone for GlobalTimer
impl Clone for GlobalTimer
Source§fn clone(&self) -> GlobalTimer
fn clone(&self) -> GlobalTimer
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for GlobalTimer
impl RefUnwindSafe for GlobalTimer
impl Send for GlobalTimer
impl Sync for GlobalTimer
impl Unpin for GlobalTimer
impl UnsafeUnpin for GlobalTimer
impl UnwindSafe for GlobalTimer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more