From bd302502d39b6172bf3db6abfa49fdcaa124ee50 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Thu, 14 Jul 2022 17:36:59 -0400 Subject: runtime: convert panicking to atomic type For #53821. Change-Id: I93409f377881a3c029b41b0f1fbcef5e21091f2f Reviewed-on: https://go-review.googlesource.com/c/go/+/419438 Reviewed-by: Austin Clements Run-TryBot: Michael Pratt TryBot-Result: Gopher Robot --- src/runtime/panic.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/runtime/panic.go') diff --git a/src/runtime/panic.go b/src/runtime/panic.go index a3e676fea4..4fadbfc2e0 100644 --- a/src/runtime/panic.go +++ b/src/runtime/panic.go @@ -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. -- cgit v1.3