From 61885b70712e643f5c487bb24a3cd7d1d55d1a9a Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Wed, 20 Jan 2021 21:03:33 -0800 Subject: [PATCH] stub in windows scheduler, get to some interesting errors --- crates/wasi-c2/cap-std-sync/src/sched.rs | 69 ++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/crates/wasi-c2/cap-std-sync/src/sched.rs b/crates/wasi-c2/cap-std-sync/src/sched.rs index 587984788e..fe87e9b7d5 100644 --- a/crates/wasi-c2/cap-std-sync/src/sched.rs +++ b/crates/wasi-c2/cap-std-sync/src/sched.rs @@ -1,5 +1,7 @@ #[cfg(unix)] pub use unix::*; +#[cfg(windows)] +pub use windows::*; #[cfg(unix)] mod unix { @@ -7,10 +9,14 @@ mod unix { use std::convert::TryInto; use std::ops::Deref; use std::os::unix::io::{AsRawFd, RawFd}; - use wasi_c2::file::WasiFile; - use wasi_c2::sched::subscription::{RwEventFlags, Subscription}; - use wasi_c2::sched::{Poll, WasiSched}; - use wasi_c2::Error; + use wasi_c2::{ + file::WasiFile, + sched::{ + subscription::{RwEventFlags, Subscription}, + Poll, WasiSched, + }, + Error, + }; use yanix::poll::{PollFd, PollFlags}; 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 { + let a = f.as_any(); + if a.is::() { + Some( + a.downcast_ref::() + .unwrap() + .as_raw_handle(), + ) + } else if a.is::() { + Some( + a.downcast_ref::() + .unwrap() + .as_raw_handle(), + ) + } else if a.is::() { + Some( + a.downcast_ref::() + .unwrap() + .as_raw_handle(), + ) + } else if a.is::() { + Some( + a.downcast_ref::() + .unwrap() + .as_raw_handle(), + ) + } else { + None + } + } +}