]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert m.preemptGen to atomic type
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 17 Aug 2022 10:36:12 +0000 (17:36 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 17 Aug 2022 17:47:37 +0000 (17:47 +0000)
Updates #53821

Change-Id: I134dac3b1eb35f2da00e5ef8f4c264f08d4f65b6
Reviewed-on: https://go-review.googlesource.com/c/go/+/423887
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>

src/runtime/os_windows.go
src/runtime/preempt.go
src/runtime/runtime2.go
src/runtime/signal_unix.go

index 2f6ec75cf89646fc0c974b5a0344caa7444457c9..54261d6fc029cade5acc56f1113f4978e2e2d4c2 100644 (file)
@@ -1326,7 +1326,7 @@ func preemptM(mp *m) {
        if !atomic.Cas(&mp.preemptExtLock, 0, 1) {
                // External code is running. Fail the preemption
                // attempt.
-               atomic.Xadd(&mp.preemptGen, 1)
+               mp.preemptGen.Add(1)
                return
        }
 
@@ -1336,7 +1336,7 @@ func preemptM(mp *m) {
                // The M hasn't been minit'd yet (or was just unminit'd).
                unlock(&mp.threadLock)
                atomic.Store(&mp.preemptExtLock, 0)
-               atomic.Xadd(&mp.preemptGen, 1)
+               mp.preemptGen.Add(1)
                return
        }
        var thread uintptr
@@ -1366,7 +1366,7 @@ func preemptM(mp *m) {
                atomic.Store(&mp.preemptExtLock, 0)
                // The thread no longer exists. This shouldn't be
                // possible, but just acknowledge the request.
-               atomic.Xadd(&mp.preemptGen, 1)
+               mp.preemptGen.Add(1)
                return
        }
 
@@ -1431,7 +1431,7 @@ func preemptM(mp *m) {
        atomic.Store(&mp.preemptExtLock, 0)
 
        // Acknowledge the preemption.
-       atomic.Xadd(&mp.preemptGen, 1)
+       mp.preemptGen.Add(1)
 
        stdcall1(_ResumeThread, thread)
        stdcall1(_CloseHandle, thread)
index da24f5042c0707eb9e7611196904843e0c8177e7..dae417215fd66ea47fbe90def1ef91710b250e42 100644 (file)
@@ -55,7 +55,6 @@ package runtime
 import (
        "internal/abi"
        "internal/goarch"
-       "runtime/internal/atomic"
 )
 
 type suspendGState struct {
@@ -192,7 +191,7 @@ func suspendG(gp *g) suspendGState {
                case _Grunning:
                        // Optimization: if there is already a pending preemption request
                        // (from the previous loop iteration), don't bother with the atomics.
-                       if gp.preemptStop && gp.preempt && gp.stackguard0 == stackPreempt && asyncM == gp.m && atomic.Load(&asyncM.preemptGen) == asyncGen {
+                       if gp.preemptStop && gp.preempt && gp.stackguard0 == stackPreempt && asyncM == gp.m && asyncM.preemptGen.Load() == asyncGen {
                                break
                        }
 
@@ -208,7 +207,7 @@ func suspendG(gp *g) suspendGState {
 
                        // Prepare for asynchronous preemption.
                        asyncM2 := gp.m
-                       asyncGen2 := atomic.Load(&asyncM2.preemptGen)
+                       asyncGen2 := asyncM2.preemptGen.Load()
                        needAsync := asyncM != asyncM2 || asyncGen != asyncGen2
                        asyncM = asyncM2
                        asyncGen = asyncGen2
index 3cf0e8e98b57c28961feebde668dff82c499666c..63ba5348158ea70cea137bc985be910cb4864e63 100644 (file)
@@ -583,8 +583,8 @@ type m struct {
 
        // preemptGen counts the number of completed preemption
        // signals. This is used to detect when a preemption is
-       // requested, but fails. Accessed atomically.
-       preemptGen uint32
+       // requested, but fails.
+       preemptGen atomic.Uint32
 
        // Whether this is a pending preemption signal on this M.
        signalPending atomic.Uint32
index 4c3f43a819acab25a1193d95e3b76f631d0f8057..545094c6403180985d86bec2fa6a7999220ae939 100644 (file)
@@ -349,7 +349,7 @@ func doSigPreempt(gp *g, ctxt *sigctxt) {
        }
 
        // Acknowledge the preemption.
-       atomic.Xadd(&gp.m.preemptGen, 1)
+       gp.m.preemptGen.Add(1)
        gp.m.signalPending.Store(0)
 
        if GOOS == "darwin" || GOOS == "ios" {