use crate::SuspendUnawareInstant;
use libc::timespec;
use std::cmp;
const NANOS_PER_SECOND: u32 = 1_000_000_000;
pub fn now() -> SuspendUnawareInstant {
let mut t: timespec = timespec {
tv_sec: 0,
tv_nsec: 0,
};
unsafe {
libc::clock_gettime(libc::CLOCK_UPTIME_RAW, &mut t);
}
t.tv_sec = cmp::max(t.tv_sec, 0);
t.tv_nsec = cmp::max(t.tv_nsec, 0);
if t.tv_nsec >= NANOS_PER_SECOND as i64 {
t.tv_nsec = 0;
}
SuspendUnawareInstant {
secs: t.tv_sec as u64,
nanos: t.tv_nsec as u32, }
}