Skip to content

Commit

Permalink
Rollup merge of rust-lang#129588 - hermit-os:sleep-micros, r=workingj…
Browse files Browse the repository at this point in the history
…ubilee

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`
  • Loading branch information
matthiaskrgr authored Aug 26, 2024
2 parents 12fe23b + c688def commit 77a1318
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion std/src/sys/pal/hermit/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 77a1318

Please sign in to comment.