mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-07 12:33:42 +00:00
runtime: move scheduler code around
This moves all scheduler code into a separate file that is only compiled
when there's a scheduler in use (the tasks or asyncify scheduler, which
are both cooperative). The main goal of this change is to make it easier
to add a new "scheduler" based on OS threads.
It also fixes a few subtle issues with `-gc=none`:
- Gosched() panicked. This is now fixed to just return immediately
(the only logical thing to do when there's only one goroutine).
- Timers aren't supported without a scheduler, but the relevant code
was still present and would happily add a timer to the queue. It
just never ran. So now it exits with a runtime error, similar to any
blocking operation.
This commit is contained in:
committed by
Ron Evans
parent
6593cf22fa
commit
d1fe02df23
@@ -33,3 +33,6 @@ func getGoroutineStackSize(fn uintptr) uintptr
|
||||
|
||||
//go:linkname runtime_alloc runtime.alloc
|
||||
func runtime_alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer
|
||||
|
||||
//go:linkname scheduleTask runtime.scheduleTask
|
||||
func scheduleTask(*Task)
|
||||
|
||||
@@ -52,7 +52,7 @@ type stackState struct {
|
||||
func start(fn uintptr, args unsafe.Pointer, stackSize uintptr) {
|
||||
t := &Task{}
|
||||
t.state.initialize(fn, args, stackSize)
|
||||
runqueuePushBack(t)
|
||||
scheduleTask(t)
|
||||
}
|
||||
|
||||
//export tinygo_launch
|
||||
@@ -82,9 +82,6 @@ func (s *state) initialize(fn uintptr, args unsafe.Pointer, stackSize uintptr) {
|
||||
s.csp = unsafe.Add(stack, stackSize)
|
||||
}
|
||||
|
||||
//go:linkname runqueuePushBack runtime.runqueuePushBack
|
||||
func runqueuePushBack(*Task)
|
||||
|
||||
// currentTask is the current running task, or nil if currently in the scheduler.
|
||||
var currentTask *Task
|
||||
|
||||
|
||||
@@ -101,15 +101,12 @@ func swapTask(oldStack uintptr, newStack *uintptr)
|
||||
//go:extern tinygo_startTask
|
||||
var startTask [0]uint8
|
||||
|
||||
//go:linkname runqueuePushBack runtime.runqueuePushBack
|
||||
func runqueuePushBack(*Task)
|
||||
|
||||
// start creates and starts a new goroutine with the given function and arguments.
|
||||
// The new goroutine is scheduled to run later.
|
||||
func start(fn uintptr, args unsafe.Pointer, stackSize uintptr) {
|
||||
t := &Task{}
|
||||
t.state.initialize(fn, args, stackSize)
|
||||
runqueuePushBack(t)
|
||||
scheduleTask(t)
|
||||
}
|
||||
|
||||
// OnSystemStack returns whether the caller is running on the system stack.
|
||||
|
||||
Reference in New Issue
Block a user