wasmx 0.0.0

High-performance, embeddable WebAssembly execution engine
Documentation
mod host;

use core::sync::atomic::Ordering;

use wasmtime::component::Linker;

use crate::{Ctx, EPOCH_MONOTONIC_NOW};

pub struct WasiClocksCtx {
    init: u64,
}

impl Default for WasiClocksCtx {
    fn default() -> Self {
        let init = EPOCH_MONOTONIC_NOW.load(Ordering::Relaxed);
        Self { init }
    }
}

/// Add all WASI interfaces from this module into the `linker` provided.
pub fn add_to_linker<T: Send>(
    linker: &mut Linker<T>,
    get: impl Fn(&mut T) -> &mut Ctx + Copy + Sync + Send + 'static,
) -> wasmtime::Result<()> {
    crate::engine::bindings::wasi::clocks::wall_clock::add_to_linker(linker, get)?;
    crate::engine::bindings::wasi::clocks::monotonic_clock::add_to_linker(linker, get)?;
    Ok(())
}