mod clock_correction;
mod clock_drift;
mod timeline_mapping;
use std::sync::OnceLock;
use std::time::Instant;
use crate::frame::ClockDomainId;
pub use clock_correction::ClockCorrectionController;
pub use clock_drift::{ClockDriftEstimator, ClockDriftSnapshot};
pub use timeline_mapping::TimelineMapping;
pub const PROCESS_MONOTONIC_CLOCK_DOMAIN_ID: ClockDomainId = ClockDomainId(1);
pub fn monotonic_timestamp_ns() -> u64 {
static ORIGIN: OnceLock<Instant> = OnceLock::new();
let elapsed_ns = ORIGIN.get_or_init(Instant::now).elapsed().as_nanos();
u64::try_from(elapsed_ns)
.unwrap_or(u64::MAX)
.saturating_add(1)
}
#[cfg(test)]
mod monotonic_clock_tests {
use super::monotonic_timestamp_ns;
#[test]
fn given_shared_monotonic_clock_when_sampled_then_value_never_moves_backwards() {
let first = monotonic_timestamp_ns();
let second = monotonic_timestamp_ns();
assert!(first > 0);
assert!(second >= first);
}
}