stub in windows scheduler, get to some interesting errors

This commit is contained in:
Pat Hickey
2021-01-20 21:03:33 -08:00
parent 7ec03631da
commit 61885b7071

View File

@@ -1,5 +1,7 @@
#[cfg(unix)] #[cfg(unix)]
pub use unix::*; pub use unix::*;
#[cfg(windows)]
pub use windows::*;
#[cfg(unix)] #[cfg(unix)]
mod unix { mod unix {
@@ -7,10 +9,14 @@ mod unix {
use std::convert::TryInto; use std::convert::TryInto;
use std::ops::Deref; use std::ops::Deref;
use std::os::unix::io::{AsRawFd, RawFd}; use std::os::unix::io::{AsRawFd, RawFd};
use wasi_c2::file::WasiFile; use wasi_c2::{
use wasi_c2::sched::subscription::{RwEventFlags, Subscription}; file::WasiFile,
use wasi_c2::sched::{Poll, WasiSched}; sched::{
use wasi_c2::Error; subscription::{RwEventFlags, Subscription},
Poll, WasiSched,
},
Error,
};
use yanix::poll::{PollFd, PollFlags}; use yanix::poll::{PollFd, PollFlags};
pub struct SyncSched; pub struct SyncSched;
@@ -126,3 +132,58 @@ mod unix {
} }
} }
} }
#[cfg(windows)]
mod windows {
use std::os::windows::io::{AsRawHandle, RawHandle};
use wasi_c2::{
file::WasiFile,
sched::{Poll, WasiSched},
Error,
};
pub struct SyncSched;
impl WasiSched for SyncSched {
fn poll_oneoff<'a>(&self, poll: &'a Poll<'a>) -> Result<(), Error> {
if poll.is_empty() {
return Ok(());
}
todo!()
}
fn sched_yield(&self) -> Result<(), Error> {
std::thread::yield_now();
Ok(())
}
}
fn wasi_file_raw_handle(f: &dyn WasiFile) -> Option<RawHandle> {
let a = f.as_any();
if a.is::<crate::file::File>() {
Some(
a.downcast_ref::<crate::file::File>()
.unwrap()
.as_raw_handle(),
)
} else if a.is::<crate::stdio::Stdin>() {
Some(
a.downcast_ref::<crate::stdio::Stdin>()
.unwrap()
.as_raw_handle(),
)
} else if a.is::<crate::stdio::Stdout>() {
Some(
a.downcast_ref::<crate::stdio::Stdout>()
.unwrap()
.as_raw_handle(),
)
} else if a.is::<crate::stdio::Stderr>() {
Some(
a.downcast_ref::<crate::stdio::Stderr>()
.unwrap()
.as_raw_handle(),
)
} else {
None
}
}
}