pub struct GlobalTimer {
pub base_timestamp: i64,
pub base_instant: Instant,
pub last_sync_at: Instant,
pub initialized: bool,
}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
initialized: boolWhether the timer has been successfully initialized
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
检查是否需要进行同步
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
获取初始化状态
Sourcepub fn set_initialized(&mut self, initialized: bool)
pub fn set_initialized(&mut self, initialized: bool)
设置初始化状态
Trait Implementations§
Source§impl Clone for GlobalTimer
impl Clone for GlobalTimer
Auto 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