scaffold a scheduler
This commit is contained in:
@@ -25,5 +25,3 @@ wasi_tests::path_filestat
|
|||||||
|
|
||||||
wasi_tests::poll_oneoff
|
wasi_tests::poll_oneoff
|
||||||
- no sched yet
|
- no sched yet
|
||||||
wasi_tests::sched_yield
|
|
||||||
- no sched yet
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::clocks::{WasiMonotonicClock, WasiSystemClock};
|
use crate::clocks::{WasiMonotonicClock, WasiSystemClock};
|
||||||
use crate::dir::{DirCaps, DirEntry, WasiDir};
|
use crate::dir::{DirCaps, DirEntry, WasiDir};
|
||||||
use crate::file::{FileCaps, FileEntry, WasiFile};
|
use crate::file::{FileCaps, FileEntry, WasiFile};
|
||||||
|
use crate::sched::{SyncSched, WasiSched};
|
||||||
use crate::string_array::{StringArray, StringArrayError};
|
use crate::string_array::{StringArray, StringArrayError};
|
||||||
use crate::table::Table;
|
use crate::table::Table;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
@@ -14,6 +15,7 @@ pub struct WasiCtx {
|
|||||||
pub(crate) env: StringArray,
|
pub(crate) env: StringArray,
|
||||||
pub(crate) random: RefCell<Box<dyn RngCore>>,
|
pub(crate) random: RefCell<Box<dyn RngCore>>,
|
||||||
pub(crate) clocks: WasiCtxClocks,
|
pub(crate) clocks: WasiCtxClocks,
|
||||||
|
pub(crate) sched: Box<dyn WasiSched>,
|
||||||
table: Rc<RefCell<Table>>,
|
table: Rc<RefCell<Table>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,6 +30,7 @@ impl WasiCtx {
|
|||||||
env: StringArray::new(),
|
env: StringArray::new(),
|
||||||
random: RefCell::new(Box::new(unsafe { cap_rand::rngs::OsRng::default() })),
|
random: RefCell::new(Box::new(unsafe { cap_rand::rngs::OsRng::default() })),
|
||||||
clocks: WasiCtxClocks::default(),
|
clocks: WasiCtxClocks::default(),
|
||||||
|
sched: Box::new(SyncSched::default()),
|
||||||
table: Rc::new(RefCell::new(Table::new())),
|
table: Rc::new(RefCell::new(Table::new())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ mod dir;
|
|||||||
mod error;
|
mod error;
|
||||||
mod file;
|
mod file;
|
||||||
pub mod random;
|
pub mod random;
|
||||||
|
pub mod sched;
|
||||||
pub mod snapshots;
|
pub mod snapshots;
|
||||||
pub mod stdio;
|
pub mod stdio;
|
||||||
mod string_array;
|
mod string_array;
|
||||||
|
|||||||
20
crates/wasi-c2/src/sched.rs
Normal file
20
crates/wasi-c2/src/sched.rs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
use crate::Error;
|
||||||
|
|
||||||
|
pub trait WasiSched {
|
||||||
|
// XXX poll oneoff needs args and results.
|
||||||
|
fn poll_oneoff(&self) -> Result<(), Error>;
|
||||||
|
fn sched_yield(&self) -> Result<(), Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct SyncSched {}
|
||||||
|
|
||||||
|
impl WasiSched for SyncSched {
|
||||||
|
fn poll_oneoff(&self) -> Result<(), Error> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
fn sched_yield(&self) -> Result<(), Error> {
|
||||||
|
std::thread::yield_now();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -886,7 +886,8 @@ impl<'a> wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
|
|||||||
events: &GuestPtr<types::Event>,
|
events: &GuestPtr<types::Event>,
|
||||||
nsubscriptions: types::Size,
|
nsubscriptions: types::Size,
|
||||||
) -> Result<types::Size, Error> {
|
) -> Result<types::Size, Error> {
|
||||||
unimplemented!()
|
self.sched.poll_oneoff()?;
|
||||||
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn proc_exit(&self, status: types::Exitcode) -> wiggle::Trap {
|
fn proc_exit(&self, status: types::Exitcode) -> wiggle::Trap {
|
||||||
@@ -903,7 +904,7 @@ impl<'a> wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn sched_yield(&self) -> Result<(), Error> {
|
fn sched_yield(&self) -> Result<(), Error> {
|
||||||
unimplemented!()
|
self.sched.sched_yield()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn random_get(&self, buf: &GuestPtr<u8>, buf_len: types::Size) -> Result<(), Error> {
|
fn random_get(&self, buf: &GuestPtr<u8>, buf_len: types::Size) -> Result<(), Error> {
|
||||||
|
|||||||
Reference in New Issue
Block a user