use std::time::Instant;
use std::{io, mem};
use libc::{CLOCK_MONOTONIC_COARSE, timespec};
use crate::pal::linux::Bindings;
#[derive(Debug, Default)]
pub(crate) struct BuildTargetBindings;
impl Bindings for BuildTargetBindings {
#[expect(
clippy::cast_sign_loss,
clippy::arithmetic_side_effects,
reason = "never going to happen with timestamps within real-universe ranges"
)]
#[inline]
fn clock_gettime_nanos(&self) -> u64 {
let mut ts: timespec = unsafe { mem::zeroed() };
let result = unsafe { libc::clock_gettime(CLOCK_MONOTONIC_COARSE, &raw mut ts) };
assert!(result == 0, "{}", io::Error::last_os_error());
ts.tv_sec as u64 * 1_000_000_000 + ts.tv_nsec as u64
}
#[inline]
fn now(&self) -> Instant {
Instant::now()
}
}
#[cfg(test)]
#[cfg_attr(coverage_nightly, coverage(off))]
mod tests {
use std::panic::{RefUnwindSafe, UnwindSafe};
use super::*;
static_assertions::assert_impl_all!(BuildTargetBindings: UnwindSafe, RefUnwindSafe);
}