Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/wasi-common/src/sync/sched.rs
1693 views
1
#[cfg(unix)]
2
pub mod unix;
3
#[cfg(unix)]
4
pub use unix::poll_oneoff;
5
6
#[cfg(windows)]
7
pub mod windows;
8
#[cfg(windows)]
9
pub use windows::poll_oneoff;
10
11
use crate::{
12
Error,
13
sched::{Poll, WasiSched},
14
};
15
use std::thread;
16
use std::time::Duration;
17
18
pub struct SyncSched {}
19
impl SyncSched {
20
pub fn new() -> Self {
21
Self {}
22
}
23
}
24
#[wiggle::async_trait]
25
impl WasiSched for SyncSched {
26
async fn poll_oneoff<'a>(&self, poll: &mut Poll<'a>) -> Result<(), Error> {
27
poll_oneoff(poll).await
28
}
29
async fn sched_yield(&self) -> Result<(), Error> {
30
thread::yield_now();
31
Ok(())
32
}
33
async fn sleep(&self, duration: Duration) -> Result<(), Error> {
34
std::thread::sleep(duration);
35
Ok(())
36
}
37
}
38
pub fn sched_ctx() -> Box<dyn WasiSched> {
39
Box::new(SyncSched::new())
40
}
41
42