starnix_sync/
atomic_time.rsuse std::sync::atomic::{AtomicI64, Ordering};
#[derive(Debug, Default)]
pub struct AtomicMonotonicInstant(AtomicI64);
impl From<zx::MonotonicInstant> for AtomicMonotonicInstant {
fn from(t: zx::MonotonicInstant) -> Self {
Self::new(t)
}
}
impl AtomicMonotonicInstant {
pub fn new(time: zx::MonotonicInstant) -> Self {
Self(AtomicI64::new(time.into_nanos()))
}
pub fn load(&self, order: Ordering) -> zx::MonotonicInstant {
let Self(atomic_time) = self;
zx::Instant::from_nanos(atomic_time.load(order))
}
pub fn store(&self, val: zx::MonotonicInstant, order: Ordering) {
let Self(atomic_time) = self;
atomic_time.store(val.into_nanos(), order)
}
}