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

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

src/runtime/mgc.go
src/runtime/panic.go
src/runtime/print.go
src/runtime/proc.go
src/runtime/signal_windows.go
src/runtime/symtab.go
src/runtime/traceback.go

index c3e91edb1fc7ad77fd168ea1a51d87b276edb0b8..1db0984906c81275febf0731f1a031cc3196cb46 100644 (file)
@@ -546,7 +546,7 @@ const (
 // that the exit condition for the _GCoff phase has been met. The exit
 // condition should be tested when allocating.
 func (t gcTrigger) test() bool {
-       if !memstats.enablegc || panicking != 0 || gcphase != _GCoff {
+       if !memstats.enablegc || panicking.Load() != 0 || gcphase != _GCoff {
                return false
        }
        switch t.kind {
index a3e676fea4f4ec03a337d4ef0882be71251c7f3a..4fadbfc2e07ee7bcaaa8a176311bf6d30fb7bfb5 100644 (file)
@@ -1071,8 +1071,7 @@ func fatal(s string) {
 var runningPanicDefers atomic.Uint32
 
 // panicking is non-zero when crashing the program for an unrecovered panic.
-// panicking is incremented and decremented atomically.
-var panicking uint32
+var panicking atomic.Uint32
 
 // paniclk is held while printing the panic information and stack trace,
 // so that two concurrent panics don't overlap their output.
@@ -1209,7 +1208,7 @@ func startpanic_m() bool {
        case 0:
                // Setting dying >0 has the side-effect of disabling this G's writebuf.
                gp.m.dying = 1
-               atomic.Xadd(&panicking, 1)
+               panicking.Add(1)
                lock(&paniclk)
                if debug.schedtrace > 0 || debug.scheddetail > 0 {
                        schedtrace(true)
@@ -1272,7 +1271,7 @@ func dopanic_m(gp *g, pc, sp uintptr) bool {
        }
        unlock(&paniclk)
 
-       if atomic.Xadd(&panicking, -1) != 0 {
+       if panicking.Add(-1) != 0 {
                // Some other m is panicking too.
                // Let it print what it needs to print.
                // Wait forever without chewing up cpu.
index b2a642bb862f00a049757bb5d2cbf0616f9fd255..a1e0b8e134e94550941ce5a0d1f3e3e0d160a799 100644 (file)
@@ -6,7 +6,6 @@ package runtime
 
 import (
        "internal/goarch"
-       "runtime/internal/atomic"
        "unsafe"
 )
 
@@ -40,7 +39,7 @@ var (
 func recordForPanic(b []byte) {
        printlock()
 
-       if atomic.Load(&panicking) == 0 {
+       if panicking.Load() == 0 {
                // Not actively crashing: maintain circular buffer of print output.
                for i := 0; i < len(b); {
                        n := copy(printBacklog[printBacklogIndex:], b[i:])
index 33219419f9a8dbf3a975bc58803bc0922abba0f2..33d7d6f552fd7d2957ce388150df16deed98d564 100644 (file)
@@ -265,7 +265,7 @@ func main() {
                        Gosched()
                }
        }
-       if atomic.Load(&panicking) != 0 {
+       if panicking.Load() != 0 {
                gopark(nil, nil, waitReasonPanicWait, traceEvGoStop, 1)
        }
 
@@ -5016,7 +5016,7 @@ func checkdead() {
        // freezetheworld will cause all running threads to block.
        // And runtime will essentially enter into deadlock state,
        // except that there is a thread that will call exit soon.
-       if panicking > 0 {
+       if panicking.Load() > 0 {
                return
        }
 
index 4a0287dcfdef6c6998be484a226d7e620307cbe0..0cf8ba8cdf5f16b50ae7c95c84246913939051cc 100644 (file)
@@ -204,10 +204,10 @@ func lastcontinuehandler(info *exceptionrecord, r *context, gp *g) int32 {
 func winthrow(info *exceptionrecord, r *context, gp *g) {
        g0 := getg()
 
-       if panicking != 0 { // traceback already printed
+       if panicking.Load() != 0 { // traceback already printed
                exit(2)
        }
-       panicking = 1
+       panicking.Store(1)
 
        // In case we're handling a g0 stack overflow, blow away the
        // g0 stack bounds so we have room to print the traceback. If
index 4a2d1d90ed489f0ade644234ced9302e120aa1e5..69190233a27cb0d77d813b50ded71b0eed3a5add 100644 (file)
@@ -902,7 +902,7 @@ func pcvalue(f funcInfo, off uint32, targetpc uintptr, cache *pcvalueCache, stri
        }
 
        if !f.valid() {
-               if strict && panicking == 0 {
+               if strict && panicking.Load() == 0 {
                        println("runtime: no module data for", hex(f.entry()))
                        throw("no module data")
                }
@@ -945,7 +945,7 @@ func pcvalue(f funcInfo, off uint32, targetpc uintptr, cache *pcvalueCache, stri
 
        // If there was a table, it should have covered all program counters.
        // If not, something is wrong.
-       if panicking != 0 || !strict {
+       if panicking.Load() != 0 || !strict {
                return -1, 0
        }
 
index 6df0bbfabebac068290e0e4898e612405bb8fcb9..96cf82c23e26d402c0abc925cf46d0935890e50c 100644 (file)
@@ -1407,7 +1407,7 @@ func printOneCgoTraceback(pc uintptr, max int, arg *cgoSymbolizerArg) int {
 // callCgoSymbolizer calls the cgoSymbolizer function.
 func callCgoSymbolizer(arg *cgoSymbolizerArg) {
        call := cgocall
-       if panicking > 0 || getg().m.curg != getg() {
+       if panicking.Load() > 0 || getg().m.curg != getg() {
                // We do not want to call into the scheduler when panicking
                // or when on the system stack.
                call = asmcgocall
@@ -1427,7 +1427,7 @@ func cgoContextPCs(ctxt uintptr, buf []uintptr) {
                return
        }
        call := cgocall
-       if panicking > 0 || getg().m.curg != getg() {
+       if panicking.Load() > 0 || getg().m.curg != getg() {
                // We do not want to call into the scheduler when panicking
                // or when on the system stack.
                call = asmcgocall