diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-08-26 17:25:32 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-26 17:25:32 +0200 |
| commit | d0b3c3a110816f0bfe609f59407b7ee9d8b13be2 (patch) | |
| tree | 8c3d9d6a8dddc07d444073c78c30236c23a02f2e | |
| parent | b1c9064071d37c4371f8cfa159e977647b66121d (diff) | |
| parent | edeefc532f645386db828a956cb50702e15f8b03 (diff) | |
| download | rust-d0b3c3a110816f0bfe609f59407b7ee9d8b13be2.tar.gz rust-d0b3c3a110816f0bfe609f59407b7ee9d8b13be2.zip | |
Rollup merge of #129588 - hermit-os:sleep-micros, r=workingjubilee
pal/hermit: correctly round up microseconds in `Thread::sleep` This fixes the Hermit-related part of https://github.com/rust-lang/rust/issues/129212 and thus the whole issue, since ESP-IDF is already fixed, as far as I understand. Fixes https://github.com/rust-lang/rust/issues/129212 r? `@workingjubilee` CC: `@stlankes`
| -rw-r--r-- | library/std/src/sys/pal/hermit/thread.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/library/std/src/sys/pal/hermit/thread.rs b/library/std/src/sys/pal/hermit/thread.rs index 6321f92e3d9..4c0c0919f47 100644 --- a/library/std/src/sys/pal/hermit/thread.rs +++ b/library/std/src/sys/pal/hermit/thread.rs @@ -77,8 +77,11 @@ impl Thread { #[inline] pub fn sleep(dur: Duration) { + let micros = dur.as_micros() + if dur.subsec_nanos() % 1_000 > 0 { 1 } else { 0 }; + let micros = u64::try_from(micros).unwrap_or(u64::MAX); + unsafe { - hermit_abi::usleep(dur.as_micros() as u64); + hermit_abi::usleep(micros); } } |
