Skip to content

Commit

Permalink
Do not loop with nfds=0, timeout=-1
Browse files Browse the repository at this point in the history
  • Loading branch information
marmistrz committed Dec 15, 2019
1 parent cc4b869 commit 37d5c4b
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions crates/wasi-common/src/sys/windows/hostcalls_impl/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,13 @@ pub(crate) fn poll_oneoff(
// With no events to listen, poll_oneoff just becomes a sleep.
if fd_events.is_empty() {
match timeout_duration {
Some(t) => {
thread::sleep(t);
return Ok(());
}
None => {
// `poll` invoked with nfds = 0, timeout = -1 appears to be an infinite sleep
// The thread is not guanteed to remain parked forever, so we need to loop
loop {
thread::park();
}
}
Some(t) => thread::sleep(t),
// `poll` invoked with nfds = 0, timeout = -1 appears to be an infinite sleep
// Even though the thread is not guanteed to remain parked forever, `poll(2)`
// mentions that spurious readiness notifications may occur, so it's probably fine
None => thread::park(),
}
return Ok(());
}

// Currently WASI file support is only (a) regular files (b) directories (c) symlinks on Windows,
Expand Down

0 comments on commit 37d5c4b

Please sign in to comment.