]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert pendingPreemptSignals to atomic type
authorMichael Pratt <mpratt@google.com>
Thu, 14 Jul 2022 20:58:25 +0000 (16:58 -0400)
committerMichael Pratt <mpratt@google.com>
Fri, 12 Aug 2022 01:31:57 +0000 (01:31 +0000)
For #53821.

Change-Id: I106adbcb00b7b887d54001c2d7d97345a13cc662
Reviewed-on: https://go-review.googlesource.com/c/go/+/419436
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>

src/runtime/proc.go
src/runtime/signal_unix.go

index 32782b3c65c8ad0d936f8c83690dc9cf7dacc9ee..cea7f37d135d6ff8f2450a8c6f0dcaf6b41ca75d 100644 (file)
@@ -1547,7 +1547,7 @@ found:
                // Make sure pendingPreemptSignals is correct when an M exits.
                // For #41702.
                if atomic.Load(&mp.signalPending) != 0 {
-                       atomic.Xadd(&pendingPreemptSignals, -1)
+                       pendingPreemptSignals.Add(-1)
                }
        }
 
@@ -4036,7 +4036,7 @@ func syscall_runtime_AfterForkInChild() {
 // pendingPreemptSignals is the number of preemption signals
 // that have been sent but not received. This is only used on Darwin.
 // For #41702.
-var pendingPreemptSignals uint32
+var pendingPreemptSignals atomic.Int32
 
 // Called from syscall package before Exec.
 //
@@ -4048,7 +4048,7 @@ func syscall_runtime_BeforeExec() {
        // On Darwin, wait for all pending preemption signals to
        // be received. See issue #41702.
        if GOOS == "darwin" || GOOS == "ios" {
-               for int32(atomic.Load(&pendingPreemptSignals)) > 0 {
+               for pendingPreemptSignals.Load() > 0 {
                        osyield()
                }
        }
index f241df69f18cc9a25aee0fa4c31e838d6ce1b307..545fe6abce6d0d74d2da78da0256b62d7cf99522 100644 (file)
@@ -353,7 +353,7 @@ func doSigPreempt(gp *g, ctxt *sigctxt) {
        atomic.Store(&gp.m.signalPending, 0)
 
        if GOOS == "darwin" || GOOS == "ios" {
-               atomic.Xadd(&pendingPreemptSignals, -1)
+               pendingPreemptSignals.Add(-1)
        }
 }
 
@@ -374,7 +374,7 @@ func preemptM(mp *m) {
 
        if atomic.Cas(&mp.signalPending, 0, 1) {
                if GOOS == "darwin" || GOOS == "ios" {
-                       atomic.Xadd(&pendingPreemptSignals, 1)
+                       pendingPreemptSignals.Add(1)
                }
 
                // If multiple threads are preempting the same M, it may send many
@@ -453,7 +453,7 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
                        // The default behavior for sigPreempt is to ignore
                        // the signal, so badsignal will be a no-op anyway.
                        if GOOS == "darwin" || GOOS == "ios" {
-                               atomic.Xadd(&pendingPreemptSignals, -1)
+                               pendingPreemptSignals.Add(-1)
                        }
                        return
                }