]> Cypherpunks repositories - gostls13.git/commitdiff
runtime, runtime/cgo: make needextram a bool
authorDavid Crawshaw <crawshaw@golang.org>
Wed, 25 Mar 2015 11:10:45 +0000 (07:10 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Thu, 26 Mar 2015 11:12:25 +0000 (11:12 +0000)
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>

src/runtime/cgo.go
src/runtime/cgo/iscgo.go
src/runtime/proc1.go
src/runtime/runtime2.go

index 7e6b253af92c2aea5aee7f75aa444d0c8edb3ad6..5dc83c0be1b31acc9e503ab005ed618a09fbf279 100644 (file)
@@ -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
index 61cba73d2221a6768d965fd64401977fbc6c14d3..54f0a1360ee0ba6d9dc8fdf945302b6a8e07b918 100644 (file)
@@ -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
index 325955665b2fed5d95bc635c6a456d52b90f56a2..4459802b158226626fd3b484a8ea44af3d78c35d 100644 (file)
@@ -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)))
index 9ea3fd197fadf9447e7ec04e5b30db4cfd54f1e5..0d3e542882ca4a62575d8346a2b89b72f52afdc2 100644 (file)
@@ -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