cap-std-sync: export ctx components

This commit is contained in:
Pat Hickey
2021-01-30 13:38:44 -08:00
parent e940d31f95
commit b6cd7d84ad
3 changed files with 14 additions and 5 deletions

View File

@@ -33,7 +33,7 @@ impl WasiMonotonicClock for MonotonicClock {
}
}
pub fn clocks() -> WasiClocks {
pub fn clocks_ctx() -> WasiClocks {
let system = Box::new(unsafe { SystemClock::new() });
let monotonic = unsafe { cap_std::time::MonotonicClock::new() };
let creation_time = monotonic.now();

View File

@@ -4,6 +4,9 @@ pub mod file;
pub mod sched;
pub mod stdio;
pub use clocks::clocks_ctx;
pub use sched::sched_ctx;
use cap_rand::RngCore;
use std::cell::RefCell;
use std::path::Path;
@@ -15,9 +18,9 @@ pub struct WasiCtxBuilder(wasi_common::WasiCtxBuilder);
impl WasiCtxBuilder {
pub fn new() -> Self {
WasiCtxBuilder(WasiCtx::builder(
random(),
clocks::clocks(),
Box::new(sched::SyncSched::new()),
random_ctx(),
clocks_ctx(),
sched_ctx(),
Rc::new(RefCell::new(Table::new())),
))
}
@@ -91,6 +94,6 @@ impl WasiCtxBuilder {
}
}
pub fn random() -> RefCell<Box<dyn RngCore>> {
pub fn random_ctx() -> RefCell<Box<dyn RngCore>> {
RefCell::new(Box::new(unsafe { cap_rand::rngs::OsRng::default() }))
}

View File

@@ -7,3 +7,9 @@ pub use unix::*;
mod windows;
#[cfg(windows)]
pub use windows::*;
use wasi_common::sched::WasiSched;
pub fn sched_ctx() -> Box<dyn WasiSched> {
Box::new(SyncSched::new())
}