runtime: prevent timer starvation in cores scheduler

This commit is contained in:
rdon-key
2026-07-14 20:44:02 +09:00
committed by Ron Evans
parent 16fc1ea2bb
commit 0fe4c619eb
+12 -12
View File
@@ -195,18 +195,6 @@ func run() {
func scheduler(_ bool) {
for mainExited.Load() == 0 {
// Check for ready-to-run tasks.
if runnable := runqueue.Pop(); runnable != nil {
// Resume it now.
setCurrentTask(runnable)
runnable.RunState = task.RunStateRunning
schedulerLock.Unlock() // unlock before resuming, Pause() will lock again
runnable.Resume()
setCurrentTask(nil)
continue
}
var now timeUnit
if sleepQueue != nil || timerQueue != nil {
now = ticks()
@@ -253,6 +241,18 @@ func scheduler(_ bool) {
}
}
// Check for ready-to-run tasks.
if runnable := runqueue.Pop(); runnable != nil {
// Resume it now.
setCurrentTask(runnable)
runnable.RunState = task.RunStateRunning
schedulerLock.Unlock() // unlock before resuming, Pause() will lock again
runnable.Resume()
setCurrentTask(nil)
continue
}
// At this point, there are no runnable tasks anymore.
// If another core is using the clock, let it handle the sleep queue.
if hasSleepingCore() {