mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 14:01:51 +00:00
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:
commit
d0b3c3a110
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user