runtime: refactor timerQueue

Move common functions to scheduler.go. They will be used both from the
cooperative and from the threads scheduler.
This commit is contained in:
Ayke van Laethem
2024-11-02 13:45:17 +01:00
committed by Ron Evans
parent 870f00222d
commit f9ed15f857
2 changed files with 32 additions and 24 deletions
+30
View File
@@ -6,6 +6,8 @@ const schedulerDebug = false
var mainExited bool
var timerQueue *timerNode
// Simple logging, for debugging.
func scheduleLog(msg string) {
if schedulerDebug {
@@ -27,6 +29,34 @@ func scheduleLogChan(msg string, ch *channel, t *task.Task) {
}
}
func timerQueueAdd(tn *timerNode) {
q := &timerQueue
for ; *q != nil; q = &(*q).next {
if tn.whenTicks() < (*q).whenTicks() {
// this will finish earlier than the next - insert here
break
}
}
tn.next = *q
*q = tn
}
func timerQueueRemove(t *timer) bool {
removedTimer := false
for q := &timerQueue; *q != nil; q = &(*q).next {
if (*q).timer == t {
scheduleLog("removed timer")
*q = (*q).next
removedTimer = true
break
}
}
if !removedTimer {
scheduleLog("did not remove timer")
}
return removedTimer
}
// Goexit terminates the currently running goroutine. No other goroutines are affected.
func Goexit() {
panicOrGoexit(nil, panicGoexit)