aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2022-07-29 14:52:42 -0400
committerMichael Pratt <mpratt@google.com>2022-08-12 01:53:29 +0000
commit3121c2bf64ae7e5c17379af2cf2a5c16952f57f1 (patch)
tree4af594226aa76d6d4a242a1e68ee107a41bfdbd2 /src
parentb04e4637dba254e5bda132753a91532f8e32e4b9 (diff)
downloadgo-3121c2bf64ae7e5c17379af2cf2a5c16952f57f1.tar.xz
runtime: convert prof.signalLock to atomic type
For #53821. Change-Id: I3e757fc6a020be10ee69459c395cb7eee49b0dfb Reviewed-on: https://go-review.googlesource.com/c/go/+/420195 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Run-TryBot: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/runtime/cpuprof.go9
-rw-r--r--src/runtime/proc.go6
2 files changed, 7 insertions, 8 deletions
diff --git a/src/runtime/cpuprof.go b/src/runtime/cpuprof.go
index 2f7f6b4153..221e021a37 100644
--- a/src/runtime/cpuprof.go
+++ b/src/runtime/cpuprof.go
@@ -14,7 +14,6 @@ package runtime
import (
"internal/abi"
- "runtime/internal/atomic"
"runtime/internal/sys"
"unsafe"
)
@@ -106,7 +105,7 @@ func SetCPUProfileRate(hz int) {
//go:nowritebarrierrec
func (p *cpuProfile) add(tagPtr *unsafe.Pointer, stk []uintptr) {
// Simple cas-lock to coordinate with setcpuprofilerate.
- for !atomic.Cas(&prof.signalLock, 0, 1) {
+ for !prof.signalLock.CompareAndSwap(0, 1) {
// TODO: Is it safe to osyield here? https://go.dev/issue/52672
osyield()
}
@@ -123,7 +122,7 @@ func (p *cpuProfile) add(tagPtr *unsafe.Pointer, stk []uintptr) {
cpuprof.log.write(tagPtr, nanotime(), hdr[:], stk)
}
- atomic.Store(&prof.signalLock, 0)
+ prof.signalLock.Store(0)
}
// addNonGo adds the non-Go stack trace to the profile.
@@ -143,7 +142,7 @@ func (p *cpuProfile) addNonGo(stk []uintptr) {
// process at a time. If not, this lock will serialize those too.
// The use of timer_create(2) on Linux to request process-targeted
// signals may have changed this.)
- for !atomic.Cas(&prof.signalLock, 0, 1) {
+ for !prof.signalLock.CompareAndSwap(0, 1) {
// TODO: Is it safe to osyield here? https://go.dev/issue/52672
osyield()
}
@@ -157,7 +156,7 @@ func (p *cpuProfile) addNonGo(stk []uintptr) {
cpuprof.lostExtra++
}
- atomic.Store(&prof.signalLock, 0)
+ prof.signalLock.Store(0)
}
// addExtra adds the "extra" profiling events,
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index c3144b4dde..a673e45071 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -4474,7 +4474,7 @@ func mcount() int32 {
}
var prof struct {
- signalLock uint32
+ signalLock atomic.Uint32
hz int32
}
@@ -4628,14 +4628,14 @@ func setcpuprofilerate(hz int32) {
// it would deadlock.
setThreadCPUProfiler(0)
- for !atomic.Cas(&prof.signalLock, 0, 1) {
+ for !prof.signalLock.CompareAndSwap(0, 1) {
osyield()
}
if prof.hz != hz {
setProcessCPUProfiler(hz)
prof.hz = hz
}
- atomic.Store(&prof.signalLock, 0)
+ prof.signalLock.Store(0)
lock(&sched.lock)
sched.profilehz = hz