Skip to content

Commit d0437b3

Browse files
committed
Fix sleep.
1 parent 37b3d27 commit d0437b3

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/libstd/sys/unix/freertos/thread.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,11 @@ impl Thread {
102102
pub fn sleep(dur: Duration) {
103103
let tick_rate = unsafe { xPortGetTickRateHz() };
104104

105-
let mut ticks_to_delay: u64 = dur
106-
.as_secs()
107-
.checked_mul(u64::from(tick_rate))
108-
.and_then(|ms| ms.checked_add(u64::from(dur.subsec_nanos() / tick_rate)))
109-
.expect("overflow converting duration to ticks");
110-
111-
while ticks_to_delay > u64::from(crate::u32::MAX) {
112-
ticks_to_delay -= u64::from(crate::u32::MAX);
105+
let mut ticks_to_delay = u128::from(dur.as_secs()) * u128::from(tick_rate)
106+
+ u128::from(((dur.subsec_millis() + 1) * tick_rate - 1)) / u128::from(tick_rate);
107+
108+
while ticks_to_delay > u128::from(crate::u32::MAX) {
109+
ticks_to_delay -= u128::from(crate::u32::MAX);
113110
unsafe { vTaskDelay(crate::u32::MAX) };
114111
}
115112

0 commit comments

Comments
 (0)