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/8082
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
_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
//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
// 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()
// 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)))
allm *m
allp [_MaxGomaxprocs + 1]*p
gomaxprocs int32
- needextram uint32
panicking uint32
goos *int8
ncpu int32
- iscgo bool
signote note
forcegc forcegcstate
sched schedt