Commit e9d9d0be authored by David Crawshaw's avatar David Crawshaw

runtime, runtime/cgo: make needextram a bool

Also invert it, which means it no longer needs to cross the cgo
package boundary.

Change-Id: I393cd073bda02b591a55d6bc6b8bb94970ea71cd
Reviewed-on: https://go-review.googlesource.com/8082Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent c5c6c3ab
......@@ -21,3 +21,10 @@ var (
_cgo_free unsafe.Pointer
_cgo_thread_start unsafe.Pointer
)
// iscgo is set to true by the runtime/cgo package
var iscgo bool
// cgoHasExtraM is set on startup when an extra M is created for cgo.
// The extra M must be created before any C/C++ code calls cgocallback.
var cgoHasExtraM bool
......@@ -15,6 +15,3 @@ import _ "unsafe" // for go:linkname
//go:linkname _iscgo runtime.iscgo
var _iscgo bool = true
//go:linkname _needextram runtime.needextram
var _needextram uint32 = 1 // create an extra M on first cgo call
......@@ -718,8 +718,8 @@ func mstart1() {
// prepare the thread to be able to handle the signals.
if _g_.m == &m0 {
// Create an extra M for callbacks on threads not created by Go.
if needextram == 1 {
needextram = 0
if iscgo && !cgoHasExtraM {
cgoHasExtraM = true
newextram()
}
initsig()
......@@ -817,7 +817,7 @@ func allocm(_p_ *p) *m {
// put the m back on the list.
//go:nosplit
func needm(x byte) {
if needextram != 0 {
if iscgo && !cgoHasExtraM {
// Can happen if C/C++ code calls Go from a global ctor.
// Can not throw, because scheduler is not initialized yet.
write(2, unsafe.Pointer(&earlycgocallback[0]), int32(len(earlycgocallback)))
......
......@@ -605,11 +605,9 @@ var (
allm *m
allp [_MaxGomaxprocs + 1]*p
gomaxprocs int32
needextram uint32
panicking uint32
goos *int8
ncpu int32
iscgo bool
signote note
forcegc forcegcstate
sched schedt
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment