internal/task: remove coroutines

This commit is contained in:
Nia Waldvogel
2021-12-31 13:36:33 -05:00
committed by Nia
parent d054d4d512
commit ea2a6b70b2
21 changed files with 41 additions and 1962 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
//go:build gc.conservative && tinygo.wasm && !scheduler.coroutines
// +build gc.conservative,tinygo.wasm,!scheduler.coroutines
//go:build gc.conservative && tinygo.wasm
// +build gc.conservative,tinygo.wasm
package task
+2 -2
View File
@@ -1,5 +1,5 @@
//go:build !gc.conservative || !tinygo.wasm || scheduler.coroutines
// +build !gc.conservative !tinygo.wasm scheduler.coroutines
//go:build !gc.conservative || !tinygo.wasm
// +build !gc.conservative !tinygo.wasm
package task
-90
View File
@@ -1,90 +0,0 @@
// +build scheduler.coroutines
package task
import (
"unsafe"
)
// rawState is an underlying coroutine state exposed by llvm.coro.
// This matches *i8 in LLVM.
type rawState uint8
//export llvm.coro.resume
func coroResume(*rawState)
type state struct{ *rawState }
//export llvm.coro.noop
func noopState() *rawState
// Resume the task until it pauses or completes.
func (t *Task) Resume() {
coroResume(t.state.rawState)
}
// setState is used by the compiler to set the state of the function at the beginning of a function call.
// Returns the state of the caller.
func (t *Task) setState(s *rawState) *rawState {
caller := t.state
t.state = state{s}
return caller.rawState
}
// returnTo is used by the compiler to return to the state of the caller.
func (t *Task) returnTo(parent *rawState) {
t.state = state{parent}
t.returnCurrent()
}
// returnCurrent is used by the compiler to return to the state of the caller in a case where the state is not replaced.
func (t *Task) returnCurrent() {
scheduleTask(t)
}
//go:linkname scheduleTask runtime.runqueuePushBack
func scheduleTask(*Task)
// setReturnPtr is used by the compiler to store the return buffer into the task.
// This buffer is where the return value of a function that is about to be called will be stored.
func (t *Task) setReturnPtr(buf unsafe.Pointer) {
t.Ptr = buf
}
// getReturnPtr is used by the compiler to get the return buffer stored into the task.
// This is called at the beginning of an async function, and the return is stored into this buffer immediately before resuming the caller.
func (t *Task) getReturnPtr() unsafe.Pointer {
return t.Ptr
}
// createTask returns a new task struct initialized with a no-op state.
func createTask() *Task {
return &Task{
state: state{noopState()},
}
}
// start invokes a function in a new goroutine. Calls to this are inserted by the compiler.
// The created goroutine starts running immediately.
// This is implemented inside the compiler.
func start(fn uintptr, args unsafe.Pointer, stackSize uintptr)
// Current returns the current active task.
// This is implemented inside the compiler.
func Current() *Task
// Pause suspends the current running task.
// This is implemented inside the compiler.
func Pause()
func fake() {
// Hack to ensure intrinsics are discovered.
Current()
Pause()
}
// OnSystemStack returns whether the caller is running on the system stack.
func OnSystemStack() bool {
// This scheduler does not do any stack switching.
return true
}
+3 -3
View File
@@ -15,13 +15,13 @@ package runtime
// closed:
// The channel is closed. Sends will panic, receives will get a zero value
// plus optionally the indication that the channel is zero (with the
// commao-ok value in the coroutine).
// comma-ok value in the task).
//
// A send/recv transmission is completed by copying from the data element of the
// sending coroutine to the data element of the receiving coroutine, and setting
// sending task to the data element of the receiving task, and setting
// the 'comma-ok' value to true.
// A receive operation on a closed channel is completed by zeroing the data
// element of the receiving coroutine and setting the 'comma-ok' value to false.
// element of the receiving task and setting the 'comma-ok' value to false.
import (
"internal/task"
+3 -7
View File
@@ -6,13 +6,9 @@ package runtime
// were added to the queue (first-in, first-out). It also contains a sleep queue
// with sleeping goroutines in order of when they should be re-activated.
//
// The scheduler is used both for the coroutine based scheduler and for the task
// based scheduler (see compiler/goroutine-lowering.go for a description). In
// both cases, the 'task' type is used to represent one goroutine. In the case
// of the task based scheduler, it literally is the goroutine itself: a pointer
// to the bottom of the stack where some important fields are kept. In the case
// of the coroutine-based scheduler, it is the coroutine pointer (a *i8 in
// LLVM).
// The scheduler is used both for the asyncify based scheduler and for the task
// based scheduler. In both cases, the 'internal/task.Task' type is used to represent one
// goroutine.
import (
"internal/task"
-9
View File
@@ -1,9 +0,0 @@
// +build scheduler.coroutines
package runtime
// getSystemStackPointer returns the current stack pointer of the system stack.
// This is always the current stack pointer.
func getSystemStackPointer() uintptr {
return getCurrentStackPointer()
}