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
|
typeLinksInitFn = typeLinksInit
|
||||||
itabsInitFn = itabsInit
|
itabsInitFn = itabsInit
|
||||||
initGoPackagesFn = initGoPackages
|
initGoPackagesFn = initGoPackages
|
||||||
|
procResizeFn = procResize
|
||||||
|
|
||||||
// A seed for the pseudo-random number generator used by getRandomData
|
// A seed for the pseudo-random number generator used by getRandomData
|
||||||
prngSeed = 0xdeadc0de
|
prngSeed = 0xdeadc0de
|
||||||
@ -44,6 +45,9 @@ func mallocInit()
|
|||||||
//go:linkname mSysStatInc runtime.mSysStatInc
|
//go:linkname mSysStatInc runtime.mSysStatInc
|
||||||
func mSysStatInc(*uint64, uintptr)
|
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()
|
// initGoPackages is an alias to main.init which recursively calls the init()
|
||||||
// methods in all imported packages. Unless this function is called, things like
|
// methods in all imported packages. Unless this function is called, things like
|
||||||
// package errors will not be properly initialized causing various problems when
|
// package errors will not be properly initialized causing various problems when
|
||||||
@ -184,11 +188,20 @@ func Init() *kernel.Error {
|
|||||||
typeLinksInitFn() // uses maps, activeModules
|
typeLinksInitFn() // uses maps, activeModules
|
||||||
itabsInitFn() // uses 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()
|
initGoPackagesFn()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetCPUCount registers the number of available CPUs with the Go runtime.
|
||||||
|
func SetCPUCount(numCPUs int32) {
|
||||||
|
procResizeFn(numCPUs)
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Dummy calls so the compiler does not optimize away the functions in
|
// Dummy calls so the compiler does not optimize away the functions in
|
||||||
// this file.
|
// this file.
|
||||||
|
@ -267,6 +267,7 @@ func TestInit(t *testing.T) {
|
|||||||
typeLinksInitFn = typeLinksInit
|
typeLinksInitFn = typeLinksInit
|
||||||
itabsInitFn = itabsInit
|
itabsInitFn = itabsInit
|
||||||
initGoPackagesFn = initGoPackages
|
initGoPackagesFn = initGoPackages
|
||||||
|
procResizeFn = procResize
|
||||||
}()
|
}()
|
||||||
|
|
||||||
mallocInitFn = func() {}
|
mallocInitFn = func() {}
|
||||||
@ -275,7 +276,7 @@ func TestInit(t *testing.T) {
|
|||||||
typeLinksInitFn = func() {}
|
typeLinksInitFn = func() {}
|
||||||
itabsInitFn = func() {}
|
itabsInitFn = func() {}
|
||||||
initGoPackagesFn = func() {}
|
initGoPackagesFn = func() {}
|
||||||
|
procResizeFn = func(_ int32) uintptr { return 0 }
|
||||||
if err := Init(); err != nil {
|
if err := Init(); err != nil {
|
||||||
t.Fatal(t)
|
t.Fatal(t)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user