Files
wasmtime/crates/wasi-common/src/clock.rs
Dan Gohman 2fdc7f1a8e [wiggle] Don't make generated structs and unions Copy.
Some structs and unions are large enough that making them `Copy` isn't
ideal. wasi-common only needed `Copy` in a few places that were easy to
fix. `SubscriptionClock` is 32 bytes, so it's not a bad a idea to pass
it by reference anyway.
2020-03-23 18:01:25 +01:00

19 lines
600 B
Rust

use crate::sys;
use crate::wasi::types::{Subclockflags, SubscriptionClock};
use crate::wasi::{Errno, Result};
use std::time::SystemTime;
pub(crate) use sys::clock::*;
pub(crate) fn to_relative_ns_delay(clock: &SubscriptionClock) -> Result<u128> {
if clock.flags != Subclockflags::SUBSCRIPTION_CLOCK_ABSTIME {
return Ok(u128::from(clock.timeout));
}
let now: u128 = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.map_err(|_| Errno::Notcapable)?
.as_nanos();
let deadline = u128::from(clock.timeout);
Ok(deadline.saturating_sub(now))
}