25 lines
579 B
Rust
25 lines
579 B
Rust
|
use core::sync::atomic::{AtomicU64, Ordering};
|
||
|
|
||
|
use yggdrasil_abi::time::SystemTime;
|
||
|
|
||
|
static MONOTONIC_MILLIS: AtomicU64 = AtomicU64::new(0);
|
||
|
|
||
|
pub fn monotonic_time() -> SystemTime {
|
||
|
let millis = MONOTONIC_MILLIS.load(Ordering::Acquire);
|
||
|
let nanoseconds = (millis % 1000) * 1000000;
|
||
|
let seconds = millis / 1000;
|
||
|
|
||
|
SystemTime {
|
||
|
seconds,
|
||
|
nanoseconds,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn add_ticks(ticks: u64) -> u64 {
|
||
|
MONOTONIC_MILLIS.fetch_add(ticks, Ordering::Release)
|
||
|
}
|
||
|
|
||
|
pub fn set_ticks(ticks: u64) -> u64 {
|
||
|
MONOTONIC_MILLIS.swap(ticks, Ordering::Release)
|
||
|
}
|