mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 11:07:46 +00:00
runtime: fix sleep duration for long sleeps
Long sleep durations weren't implemented correctly, by simply casting to a smaller number of bits. What we want is a saturating downcast, which is what I've used here instead. This should fix https://github.com/tinygo-org/tinygo/issues/3356.
This commit is contained in:
committed by
Ron Evans
parent
faf455283d
commit
8872d5ebfc
@@ -273,6 +273,9 @@ func nanosecondsToTicks(ns int64) timeUnit {
|
||||
func sleepTicks(d timeUnit) {
|
||||
for d != 0 {
|
||||
ticks := uint32(d)
|
||||
if d > 0xffff_ffff {
|
||||
ticks = 0xffff_ffff
|
||||
}
|
||||
if !timerSleep(ticks) {
|
||||
// Bail out early to handle a non-time interrupt.
|
||||
return
|
||||
|
||||
@@ -266,6 +266,9 @@ func nanosecondsToTicks(ns int64) timeUnit {
|
||||
func sleepTicks(d timeUnit) {
|
||||
for d != 0 {
|
||||
ticks := uint32(d)
|
||||
if d > 0xffff_ffff {
|
||||
ticks = 0xffff_ffff
|
||||
}
|
||||
if !timerSleep(ticks) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -78,6 +78,9 @@ func buffered() int {
|
||||
func sleepTicks(d timeUnit) {
|
||||
for d != 0 {
|
||||
ticks := uint32(d) & 0x7fffff // 23 bits (to be on the safe side)
|
||||
if d > 0x7fffff {
|
||||
ticks = 0x7fffff
|
||||
}
|
||||
rtc_sleep(ticks)
|
||||
d -= timeUnit(ticks)
|
||||
}
|
||||
|
||||
@@ -81,6 +81,9 @@ func buffered() int {
|
||||
func sleepTicks(d timeUnit) {
|
||||
for d != 0 {
|
||||
ticks := uint32(d) & 0x7fffff // 23 bits (to be on the safe side)
|
||||
if d > 0x7fffff {
|
||||
ticks = 0x7fffff
|
||||
}
|
||||
rtc_sleep(ticks)
|
||||
d -= timeUnit(ticks)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user