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`
This commit is contained in:
Matthias Krüger 2024-08-26 17:25:32 +02:00 committed by GitHub
commit d0b3c3a110
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 1 deletions

View File

@ -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);
}
}