]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime: convert prof.signalLock to atomic type
authorMichael Pratt <mpratt@google.com>
Fri, 29 Jul 2022 18:52:42 +0000 (14:52 -0400)
committerMichael Pratt <mpratt@google.com>
Fri, 12 Aug 2022 01:53:29 +0000 (01:53 +0000)
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>

src/runtime/cpuprof.go
src/runtime/proc.go

index 2f7f6b4153eb15aa4ed3d8362d5ff7c4d944740f..221e021a3762abffeb594dd65e785e7ae2e8cbd6 100644 (file)
@@ -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,
index c3144b4ddedee4565a3fdbf4d20268e3492cda8b..a673e4507121ce0eb844940a5558a650350dc20d 100644 (file)
@@ -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