wasi: make WasiSched::sleep fallible
some systems do not support sleeping and may want to return EINVAL here.
This commit is contained in:
@@ -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(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user