Merge pull request #2756 from bytecodealliance/pch/wasi_sleep_fallible

wasi: make WasiSched::sleep fallible
This commit is contained in:
Pat Hickey
2021-03-23 14:40:21 -07:00
committed by GitHub
5 changed files with 9 additions and 9 deletions

View File

@@ -108,8 +108,9 @@ impl WasiSched for SyncSched {
std::thread::yield_now(); std::thread::yield_now();
Ok(()) Ok(())
} }
fn sleep(&self, duration: Duration) { fn sleep(&self, duration: Duration) -> Result<(), Error> {
std::thread::sleep(duration) std::thread::sleep(duration);
Ok(())
} }
} }

View File

@@ -128,8 +128,9 @@ impl WasiSched for SyncSched {
thread::yield_now(); thread::yield_now();
Ok(()) Ok(())
} }
fn sleep(&self, duration: Duration) { fn sleep(&self, duration: Duration) -> Result<(), Error> {
std::thread::sleep(duration) std::thread::sleep(duration);
Ok(())
} }
} }

View File

@@ -10,7 +10,7 @@ use subscription::{MonotonicClockSubscription, RwSubscription, Subscription, Sub
pub trait WasiSched { pub trait WasiSched {
fn poll_oneoff(&self, poll: &Poll) -> Result<(), Error>; fn poll_oneoff(&self, poll: &Poll) -> Result<(), Error>;
fn sched_yield(&self) -> Result<(), Error>; fn sched_yield(&self) -> Result<(), Error>;
fn sleep(&self, duration: Duration); fn sleep(&self, duration: Duration) -> Result<(), Error>;
} }
pub struct Userdata(u64); pub struct Userdata(u64);

View File

@@ -749,8 +749,7 @@ impl<'a> wasi_unstable::WasiUnstable for WasiCtx {
.flags .flags
.contains(types::Subclockflags::SUBSCRIPTION_CLOCK_ABSTIME) .contains(types::Subclockflags::SUBSCRIPTION_CLOCK_ABSTIME)
{ {
self.sched.sleep(Duration::from_nanos(clocksub.timeout)); self.sched.sleep(Duration::from_nanos(clocksub.timeout))?;
events.write(types::Event { events.write(types::Event {
userdata: sub.userdata, userdata: sub.userdata,
error: types::Errno::Success, error: types::Errno::Success,

View File

@@ -920,8 +920,7 @@ impl<'a> wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
.flags .flags
.contains(types::Subclockflags::SUBSCRIPTION_CLOCK_ABSTIME) .contains(types::Subclockflags::SUBSCRIPTION_CLOCK_ABSTIME)
{ {
self.sched.sleep(Duration::from_nanos(clocksub.timeout)); self.sched.sleep(Duration::from_nanos(clocksub.timeout))?;
events.write(types::Event { events.write(types::Event {
userdata: sub.userdata, userdata: sub.userdata,
error: types::Errno::Success, error: types::Errno::Success,