From edeefc532f645386db828a956cb50702e15f8b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 26 Aug 2024 00:04:00 +0200 Subject: [PATCH] pal/hermit: saturate `usleep` microseconds at `u64::MAX` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- library/std/src/sys/pal/hermit/thread.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/std/src/sys/pal/hermit/thread.rs b/library/std/src/sys/pal/hermit/thread.rs index bc70b3ac170..4c0c0919f47 100644 --- a/library/std/src/sys/pal/hermit/thread.rs +++ b/library/std/src/sys/pal/hermit/thread.rs @@ -78,9 +78,10 @@ pub fn set_name(_name: &CStr) { #[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(micros as u64); + hermit_abi::usleep(micros); } }