runtime: make channels work in interrupts

This commit is contained in:
Jaden Weiss
2020-05-29 23:46:58 -04:00
committed by Ron Evans
parent aa3481e06a
commit a4f3457747
13 changed files with 232 additions and 33 deletions
+8 -7
View File
@@ -20,6 +20,8 @@ import (
const schedulerDebug = false
var schedulerDone bool
// Queues used by the scheduler.
var (
runqueue task.Queue
@@ -114,7 +116,7 @@ func addSleepTask(t *task.Task, duration timeUnit) {
func scheduler() {
// Main scheduler loop.
var now timeUnit
for {
for !schedulerDone {
scheduleLog("")
scheduleLog(" schedule")
if sleepQueue != nil {
@@ -135,12 +137,11 @@ func scheduler() {
t := runqueue.Pop()
if t == nil {
if sleepQueue == nil {
// No more tasks to execute.
// It would be nice if we could detect deadlocks here, because
// there might still be functions waiting on each other in a
// deadlock.
scheduleLog(" no tasks left!")
return
if asyncScheduler {
return
}
waitForEvents()
continue
}
timeLeft := timeUnit(sleepQueue.Data) - (now - sleepQueueBaseTime)
if schedulerDebug {