runtime: handle negative sleep times

This change fixes the edge case where a negative sleep time is provided.
When this happens, the call now returns immediately (as specified by the docs for time.Sleep).
This commit is contained in:
Nia Waldvogel
2021-12-15 10:39:56 -05:00
committed by Ron Evans
parent 929cd767c1
commit c096f35224
3 changed files with 15 additions and 0 deletions
+5
View File
@@ -1,3 +1,4 @@
//go:build !scheduler.none
// +build !scheduler.none
package runtime
@@ -7,6 +8,10 @@ import "internal/task"
// Pause the current task for a given time.
//go:linkname sleep time.Sleep
func sleep(duration int64) {
if duration <= 0 {
return
}
addSleepTask(task.Current(), nanosecondsToTicks(duration))
task.Pause()
}
+5
View File
@@ -1,9 +1,14 @@
//go:build scheduler.none
// +build scheduler.none
package runtime
//go:linkname sleep time.Sleep
func sleep(duration int64) {
if duration <= 0 {
return
}
sleepTicks(nanosecondsToTicks(duration))
}