
This is a big change that will determine the stack size for many goroutines automatically. Functions that aren't recursive and don't call function pointers can in many cases have an automatically determined worst case stack size. This is useful, as the stack size is usually much lower than the previous hardcoded default of 1024 bytes: somewhere around 200-500 bytes is common. A side effect of this change is that the default stack sizes (including the stack size for other architectures such as AVR) can now be changed in the config JSON file, making it tunable per application.
25 строки
694 Б
Go
25 строки
694 Б
Go
package task
|
|
|
|
import (
|
|
"unsafe"
|
|
)
|
|
|
|
// Task is a state of goroutine for scheduling purposes.
|
|
type Task struct {
|
|
// Next is a field which can be used to make a linked list of tasks.
|
|
Next *Task
|
|
|
|
// Ptr is a field which can be used for storing a pointer.
|
|
Ptr unsafe.Pointer
|
|
|
|
// Data is a field which can be used for storing state information.
|
|
Data uint
|
|
|
|
// state is the underlying running state of the task.
|
|
state state
|
|
}
|
|
|
|
// getGoroutineStackSize is a compiler intrinsic that returns the stack size for
|
|
// the given function and falls back to the default stack size. It is replaced
|
|
// with a load from a special section just before codegen.
|
|
func getGoroutineStackSize(fn uintptr) uintptr
|