]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert mOS.profileTimerValid to internal atomic type
authorAndy Pan <panjf2000@gmail.com>
Sat, 27 Aug 2022 18:24:06 +0000 (02:24 +0800)
committerGopher Robot <gobot@golang.org>
Wed, 31 Aug 2022 15:12:21 +0000 (15:12 +0000)
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>
src/runtime/os_linux.go

index 25aea6522dc5fc2f64a892bf85463843a361253d..3ae665c83d867a923223ea52156e2763eceaa757 100644 (file)
@@ -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