Skip to content

Commit 0ac9e59

Browse files
committed
Auto merge of #150291 - alexcrichton:wasi-use-usleep, r=ChrisDenton
std: Use `usleep` temporarily on WASI targets This fixes some fallout from #147572 where the `thread::sleep` function is is broken on `wasm32-wasip2` after that PR. The cause for this is a broken implementation of `nanosleep` in wasi-libc itself which is being fixed in WebAssembly/wasi-libc#696. Similar to #149864 this avoids the problematic function for now while the wasi-libc changes take some time to propagate into a wasi-sdk release. Closes #150290
2 parents 5c53093 + dfbb0fd commit 0ac9e59

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

library/std/src/sys/thread/unix.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ pub fn set_name(name: &CStr) {
520520
debug_assert_eq!(res, libc::OK);
521521
}
522522

523-
#[cfg(not(target_os = "espidf"))]
523+
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
524524
pub fn sleep(dur: Duration) {
525525
let mut secs = dur.as_secs();
526526
let mut nsecs = dur.subsec_nanos() as _;
@@ -546,7 +546,13 @@ pub fn sleep(dur: Duration) {
546546
}
547547
}
548548

549-
#[cfg(target_os = "espidf")]
549+
#[cfg(any(
550+
target_os = "espidf",
551+
// wasi-libc prior to WebAssembly/wasi-libc#696 has a broken implementation
552+
// of `nanosleep`, used above by most platforms, so use `usleep` until
553+
// that fix propagates throughout the ecosystem.
554+
target_os = "wasi",
555+
))]
550556
pub fn sleep(dur: Duration) {
551557
// ESP-IDF does not have `nanosleep`, so we use `usleep` instead.
552558
// As per the documentation of `usleep`, it is expected to support

0 commit comments

Comments
 (0)