Skip to content

Commit 77a1318

Browse files
authored
Rollup merge of rust-lang#129588 - hermit-os:sleep-micros, r=workingjubilee
pal/hermit: correctly round up microseconds in `Thread::sleep` This fixes the Hermit-related part of rust-lang#129212 and thus the whole issue, since ESP-IDF is already fixed, as far as I understand. Fixes rust-lang#129212 r? `@workingjubilee` CC: `@stlankes`
2 parents 12fe23b + c688def commit 77a1318

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Diff for: std/src/sys/pal/hermit/thread.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ impl Thread {
7777

7878
#[inline]
7979
pub fn sleep(dur: Duration) {
80+
let micros = dur.as_micros() + if dur.subsec_nanos() % 1_000 > 0 { 1 } else { 0 };
81+
let micros = u64::try_from(micros).unwrap_or(u64::MAX);
82+
8083
unsafe {
81-
hermit_abi::usleep(dur.as_micros() as u64);
84+
hermit_abi::usleep(micros);
8285
}
8386
}
8487

0 commit comments

Comments
 (0)