Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasi: make WasiSched::sleep fallible #2756

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/wasi-common/cap-std-sync/src/sched/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ impl WasiSched for SyncSched {
std::thread::yield_now();
Ok(())
}
fn sleep(&self, duration: Duration) {
std::thread::sleep(duration)
fn sleep(&self, duration: Duration) -> Result<(), Error> {
std::thread::sleep(duration);
Ok(())
}
}

Expand Down
5 changes: 3 additions & 2 deletions crates/wasi-common/cap-std-sync/src/sched/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ impl WasiSched for SyncSched {
thread::yield_now();
Ok(())
}
fn sleep(&self, duration: Duration) {
std::thread::sleep(duration)
fn sleep(&self, duration: Duration) -> Result<(), Error> {
std::thread::sleep(duration);
Ok(())
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-common/src/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use subscription::{MonotonicClockSubscription, RwSubscription, Subscription, Sub
pub trait WasiSched {
fn poll_oneoff(&self, poll: &Poll) -> Result<(), Error>;
fn sched_yield(&self) -> Result<(), Error>;
fn sleep(&self, duration: Duration);
fn sleep(&self, duration: Duration) -> Result<(), Error>;
}

pub struct Userdata(u64);
Expand Down
3 changes: 1 addition & 2 deletions crates/wasi-common/src/snapshots/preview_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,7 @@ impl<'a> wasi_unstable::WasiUnstable for WasiCtx {
.flags
.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 {
userdata: sub.userdata,
error: types::Errno::Success,
Expand Down
3 changes: 1 addition & 2 deletions crates/wasi-common/src/snapshots/preview_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,7 @@ impl<'a> wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
.flags
.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 {
userdata: sub.userdata,
error: types::Errno::Success,
Expand Down