import (
"internal/abi"
- "runtime/internal/atomic"
"runtime/internal/sys"
"unsafe"
)
//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()
}
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.
// 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()
}
cpuprof.lostExtra++
}
- atomic.Store(&prof.signalLock, 0)
+ prof.signalLock.Store(0)
}
// addExtra adds the "extra" profiling events,
}
var prof struct {
- signalLock uint32
+ signalLock atomic.Uint32
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