use core::{
sync::atomic::{AtomicU64, Ordering},
time::Duration,
};
use crate::arch::timer::TIMER_FREQ;
#[derive(Copy, Clone, Debug)]
pub struct Jiffies(u64);
pub(crate) static ELAPSED: AtomicU64 = AtomicU64::new(0);
impl Jiffies {
pub fn new(value: u64) -> Self {
Self(value)
}
pub fn elapsed() -> Self {
Self::new(ELAPSED.load(Ordering::Relaxed))
}
pub fn as_u64(self) -> u64 {
self.0
}
pub fn as_duration(self) -> Duration {
Duration::from_millis(self.0 * 1000 / TIMER_FREQ)
}
}
impl From<Jiffies> for Duration {
fn from(value: Jiffies) -> Self {
value.as_duration()
}
}