mirror of
https://github.com/taigrr/gopher-os
synced 2025-01-18 04:43:13 -08:00
Enable support for deferred calls
This commit is contained in:
parent
9567f259bd
commit
ccba8877ce
@ -21,6 +21,7 @@ var (
|
||||
typeLinksInitFn = typeLinksInit
|
||||
itabsInitFn = itabsInit
|
||||
initGoPackagesFn = initGoPackages
|
||||
procResizeFn = procResize
|
||||
|
||||
// A seed for the pseudo-random number generator used by getRandomData
|
||||
prngSeed = 0xdeadc0de
|
||||
@ -44,6 +45,9 @@ func mallocInit()
|
||||
//go:linkname mSysStatInc runtime.mSysStatInc
|
||||
func mSysStatInc(*uint64, uintptr)
|
||||
|
||||
//go:linkname procResize runtime.procresize
|
||||
func procResize(int32) uintptr
|
||||
|
||||
// initGoPackages is an alias to main.init which recursively calls the init()
|
||||
// methods in all imported packages. Unless this function is called, things like
|
||||
// package errors will not be properly initialized causing various problems when
|
||||
@ -184,11 +188,20 @@ func Init() *kernel.Error {
|
||||
typeLinksInitFn() // uses maps, activeModules
|
||||
itabsInitFn() // uses activeModules
|
||||
|
||||
// Set processor count to 1. This initializes the p pointer in the
|
||||
// currently active m allowing the kernel to register defer functions
|
||||
SetCPUCount(1)
|
||||
|
||||
initGoPackagesFn()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetCPUCount registers the number of available CPUs with the Go runtime.
|
||||
func SetCPUCount(numCPUs int32) {
|
||||
procResizeFn(numCPUs)
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Dummy calls so the compiler does not optimize away the functions in
|
||||
// this file.
|
||||
|
@ -267,6 +267,7 @@ func TestInit(t *testing.T) {
|
||||
typeLinksInitFn = typeLinksInit
|
||||
itabsInitFn = itabsInit
|
||||
initGoPackagesFn = initGoPackages
|
||||
procResizeFn = procResize
|
||||
}()
|
||||
|
||||
mallocInitFn = func() {}
|
||||
@ -275,7 +276,7 @@ func TestInit(t *testing.T) {
|
||||
typeLinksInitFn = func() {}
|
||||
itabsInitFn = func() {}
|
||||
initGoPackagesFn = func() {}
|
||||
|
||||
procResizeFn = func(_ int32) uintptr { return 0 }
|
||||
if err := Init(); err != nil {
|
||||
t.Fatal(t)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user