]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert runningPanicDefers to atomic type
authorMichael Pratt <mpratt@google.com>
Thu, 14 Jul 2022 21:29:29 +0000 (17:29 -0400)
committerMichael Pratt <mpratt@google.com>
Fri, 12 Aug 2022 01:38:41 +0000 (01:38 +0000)
For #53821.

Change-Id: Ib48a1f2ff85d667c86dbd0b7662efab5a0abd837
Reviewed-on: https://go-review.googlesource.com/c/go/+/419437
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/panic.go
src/runtime/proc.go

index 3783e3dedee5723a818d39fa52e7b8827abb1860..a3e676fea4f4ec03a337d4ef0882be71251c7f3a 100644 (file)
@@ -837,7 +837,7 @@ func gopanic(e any) {
        p.link = gp._panic
        gp._panic = (*_panic)(noescape(unsafe.Pointer(&p)))
 
-       atomic.Xadd(&runningPanicDefers, 1)
+       runningPanicDefers.Add(1)
 
        // By calculating getcallerpc/getcallersp here, we avoid scanning the
        // gopanic frame (stack scanning is slow...)
@@ -917,7 +917,7 @@ func gopanic(e any) {
                                mcall(recovery)
                                throw("bypassed recovery failed") // mcall should not return
                        }
-                       atomic.Xadd(&runningPanicDefers, -1)
+                       runningPanicDefers.Add(-1)
 
                        // After a recover, remove any remaining non-started,
                        // open-coded defer entries, since the corresponding defers
@@ -1067,9 +1067,8 @@ func fatal(s string) {
 }
 
 // runningPanicDefers is non-zero while running deferred functions for panic.
-// runningPanicDefers is incremented and decremented atomically.
 // This is used to try hard to get a panic stack trace out when exiting.
-var runningPanicDefers uint32
+var runningPanicDefers atomic.Uint32
 
 // panicking is non-zero when crashing the program for an unrecovered panic.
 // panicking is incremented and decremented atomically.
@@ -1155,7 +1154,7 @@ func fatalpanic(msgs *_panic) {
                        // startpanic_m set panicking, which will
                        // block main from exiting, so now OK to
                        // decrement runningPanicDefers.
-                       atomic.Xadd(&runningPanicDefers, -1)
+                       runningPanicDefers.Add(-1)
 
                        printpanics(msgs)
                }
index cea7f37d135d6ff8f2450a8c6f0dcaf6b41ca75d..33219419f9a8dbf3a975bc58803bc0922abba0f2 100644 (file)
@@ -256,10 +256,10 @@ func main() {
        // another goroutine at the same time as main returns,
        // let the other goroutine finish printing the panic trace.
        // Once it does, it will exit. See issues 3934 and 20018.
-       if atomic.Load(&runningPanicDefers) != 0 {
+       if runningPanicDefers.Load() != 0 {
                // Running deferred functions should not take long.
                for c := 0; c < 1000; c++ {
-                       if atomic.Load(&runningPanicDefers) == 0 {
+                       if runningPanicDefers.Load() == 0 {
                                break
                        }
                        Gosched()