reuse cap-std-syncs windows scheduler without copypaste

This commit is contained in:
Pat Hickey
2021-05-06 15:45:54 -07:00
parent 3d9b98f1df
commit ff8bdc390b
4 changed files with 212 additions and 410 deletions

View File

@@ -1,15 +1,40 @@
#[cfg(unix)]
mod unix;
pub mod unix;
#[cfg(unix)]
pub use unix::*;
pub use unix::poll_oneoff;
#[cfg(windows)]
mod windows;
pub mod windows;
#[cfg(windows)]
pub use windows::*;
pub use windows::poll_oneoff;
use wasi_common::sched::WasiSched;
use std::thread;
use std::time::Duration;
use wasi_common::{
sched::{Poll, WasiSched},
Error,
};
pub struct SyncSched {}
impl SyncSched {
pub fn new() -> Self {
Self {}
}
}
#[async_trait::async_trait(?Send)]
impl WasiSched for SyncSched {
async fn poll_oneoff<'a>(&self, poll: &mut Poll<'a>) -> Result<(), Error> {
poll_oneoff(poll).await
}
async fn sched_yield(&self) -> Result<(), Error> {
thread::yield_now();
Ok(())
}
async fn sleep(&self, duration: Duration) -> Result<(), Error> {
std::thread::sleep(duration);
Ok(())
}
}
pub fn sched_ctx() -> Box<dyn WasiSched> {
Box::new(SyncSched::new())
}