run init in a goroutine
Этот коммит содержится в:
родитель
5d869f6042
коммит
0759b70c50
7 изменённых файлов: 21 добавлений и 7 удалений
|
@ -180,7 +180,7 @@ func (b gcBlock) unmark() {
|
||||||
// No memory may be allocated before this is called. That means the runtime and
|
// No memory may be allocated before this is called. That means the runtime and
|
||||||
// any packages the runtime depends upon may not allocate memory during package
|
// any packages the runtime depends upon may not allocate memory during package
|
||||||
// initialization.
|
// initialization.
|
||||||
func init() {
|
func initHeap() {
|
||||||
totalSize := heapEnd - heapStart
|
totalSize := heapEnd - heapStart
|
||||||
|
|
||||||
// Allocate some memory to keep 2 bits of information about every block.
|
// Allocate some memory to keep 2 bits of information about every block.
|
||||||
|
|
|
@ -45,3 +45,7 @@ func KeepAlive(x interface{}) {
|
||||||
func SetFinalizer(obj interface{}, finalizer interface{}) {
|
func SetFinalizer(obj interface{}, finalizer interface{}) {
|
||||||
// Unimplemented.
|
// Unimplemented.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initHeap() {
|
||||||
|
// Nothing to initialize.
|
||||||
|
}
|
||||||
|
|
|
@ -27,3 +27,7 @@ func KeepAlive(x interface{}) {
|
||||||
func SetFinalizer(obj interface{}, finalizer interface{}) {
|
func SetFinalizer(obj interface{}, finalizer interface{}) {
|
||||||
// Unimplemented.
|
// Unimplemented.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initHeap() {
|
||||||
|
// Nothing to initialize.
|
||||||
|
}
|
||||||
|
|
|
@ -26,10 +26,7 @@ func clock_gettime(clk_id int32, ts *timespec)
|
||||||
|
|
||||||
const heapSize = 1 * 1024 * 1024 // 1MB to start
|
const heapSize = 1 * 1024 * 1024 // 1MB to start
|
||||||
|
|
||||||
var (
|
var heapStart, heapEnd uintptr
|
||||||
heapStart = uintptr(malloc(heapSize))
|
|
||||||
heapEnd = heapStart + heapSize
|
|
||||||
)
|
|
||||||
|
|
||||||
type timeUnit int64
|
type timeUnit int64
|
||||||
|
|
||||||
|
@ -50,6 +47,9 @@ func postinit() {}
|
||||||
// Entry point for Go. Initialize all packages and call main.main().
|
// Entry point for Go. Initialize all packages and call main.main().
|
||||||
//go:export main
|
//go:export main
|
||||||
func main() int {
|
func main() int {
|
||||||
|
heapStart = uintptr(malloc(heapSize))
|
||||||
|
heapEnd = heapStart + heapSize
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
|
||||||
// For libc compatibility.
|
// For libc compatibility.
|
||||||
|
|
|
@ -22,6 +22,10 @@ func postinit() {}
|
||||||
|
|
||||||
//export _start
|
//export _start
|
||||||
func _start() {
|
func _start() {
|
||||||
|
// These need to be initialized early so that the heap can be initialized.
|
||||||
|
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
|
||||||
|
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
|
||||||
|
|
||||||
run()
|
run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,10 @@ func sleep(duration int64) {
|
||||||
// run is called by the program entry point to execute the go program.
|
// run is called by the program entry point to execute the go program.
|
||||||
// With a scheduler, init and the main function are invoked in a goroutine before starting the scheduler.
|
// With a scheduler, init and the main function are invoked in a goroutine before starting the scheduler.
|
||||||
func run() {
|
func run() {
|
||||||
initAll()
|
initHeap()
|
||||||
postinit()
|
|
||||||
go func() {
|
go func() {
|
||||||
|
initAll()
|
||||||
|
postinit()
|
||||||
callMain()
|
callMain()
|
||||||
}()
|
}()
|
||||||
scheduler()
|
scheduler()
|
||||||
|
|
|
@ -16,6 +16,7 @@ func getSystemStackPointer() uintptr {
|
||||||
// run is called by the program entry point to execute the go program.
|
// run is called by the program entry point to execute the go program.
|
||||||
// With the "none" scheduler, init and the main function are invoked directly.
|
// With the "none" scheduler, init and the main function are invoked directly.
|
||||||
func run() {
|
func run() {
|
||||||
|
initHeap()
|
||||||
initAll()
|
initAll()
|
||||||
postinit()
|
postinit()
|
||||||
callMain()
|
callMain()
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче