1
0
mirror of https://github.com/golang/go synced 2024-11-17 20:44:47 -07:00

runtime: convert pendingPreemptSignals to atomic type

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>
This commit is contained in:
Michael Pratt 2022-07-14 16:58:25 -04:00
parent a5cd894318
commit 40fa2dabe0
2 changed files with 6 additions and 6 deletions

View 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()
}
}

View 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
}