aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/os_linux.go
diff options
context:
space:
mode:
authorAndy Pan <panjf2000@gmail.com>2022-08-28 02:24:06 +0800
committerGopher Robot <gobot@golang.org>2022-08-31 15:12:21 +0000
commitd3b35a42429cec6d57d0d1e167d9443d0fbd6e97 (patch)
tree9824f4c980a38ae40f447b6d6cbc57648a8a4236 /src/runtime/os_linux.go
parent28e388589b48063047dbe7738bc1dfd4ed8e36bd (diff)
downloadgo-d3b35a42429cec6d57d0d1e167d9443d0fbd6e97.tar.xz
runtime: convert mOS.profileTimerValid to internal atomic type
For #53821 Change-Id: I6ef90867e918d4907baa83c5a811f1f93e8c09a5 Reviewed-on: https://go-review.googlesource.com/c/go/+/426196 Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/os_linux.go')
-rw-r--r--src/runtime/os_linux.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/runtime/os_linux.go b/src/runtime/os_linux.go
index 25aea6522d..3ae665c83d 100644
--- a/src/runtime/os_linux.go
+++ b/src/runtime/os_linux.go
@@ -21,12 +21,12 @@ type mOS struct {
// profileTimer holds the ID of the POSIX interval timer for profiling CPU
// usage on this thread.
//
- // It is valid when the profileTimerValid field is non-zero. A thread
+ // It is valid when the profileTimerValid field is true. A thread
// creates and manages its own timer, and these fields are read and written
// only by this thread. But because some of the reads on profileTimerValid
- // are in signal handling code, access to that field uses atomic operations.
+ // are in signal handling code, this field should be atomic type.
profileTimer int32
- profileTimerValid uint32
+ profileTimerValid atomic.Bool
// needPerThreadSyscall indicates that a per-thread syscall is required
// for doAllThreadsSyscall.
@@ -593,7 +593,7 @@ func validSIGPROF(mp *m, c *sigctxt) bool {
// Having an M means the thread interacts with the Go scheduler, and we can
// check whether there's an active per-thread timer for this thread.
- if atomic.Load(&mp.profileTimerValid) != 0 {
+ if mp.profileTimerValid.Load() {
// If this M has its own per-thread CPU profiling interval timer, we
// should track the SIGPROF signals that come from that timer (for
// accurate reporting of its CPU usage; see issue 35057) and ignore any
@@ -619,9 +619,9 @@ func setThreadCPUProfiler(hz int32) {
}
// destroy any active timer
- if atomic.Load(&mp.profileTimerValid) != 0 {
+ if mp.profileTimerValid.Load() {
timerid := mp.profileTimer
- atomic.Store(&mp.profileTimerValid, 0)
+ mp.profileTimerValid.Store(false)
mp.profileTimer = 0
ret := timer_delete(timerid)
@@ -681,7 +681,7 @@ func setThreadCPUProfiler(hz int32) {
}
mp.profileTimer = timerid
- atomic.Store(&mp.profileTimerValid, 1)
+ mp.profileTimerValid.Store(true)
}
// perThreadSyscallArgs contains the system call number, arguments, and