From 301ca7513f427f6511fb67cc0385151403cd1729 Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Fri, 26 Aug 2022 10:41:32 +0800 Subject: [PATCH] runtime: convert worldIsStopped to atomic type For #53821 Change-Id: I246b65ddb1171d2cab42f98092c64f20ecef392a Reviewed-on: https://go-review.googlesource.com/c/go/+/425778 Run-TryBot: Michael Pratt Reviewed-by: Heschi Kreinick TryBot-Result: Gopher Robot Reviewed-by: Michael Pratt --- src/runtime/lockrank_on.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/runtime/lockrank_on.go b/src/runtime/lockrank_on.go index 23adad7660..5dcc79b15e 100644 --- a/src/runtime/lockrank_on.go +++ b/src/runtime/lockrank_on.go @@ -13,7 +13,7 @@ import ( // worldIsStopped is accessed atomically to track world-stops. 1 == world // stopped. -var worldIsStopped uint32 +var worldIsStopped atomic.Uint32 // lockRankStruct is embedded in mutex type lockRankStruct struct { @@ -301,7 +301,7 @@ func assertRankHeld(r lockRank) { // //go:nosplit func worldStopped() { - if stopped := atomic.Xadd(&worldIsStopped, 1); stopped != 1 { + if stopped := worldIsStopped.Add(1); stopped != 1 { systemstack(func() { print("world stop count=", stopped, "\n") throw("recursive world stop") @@ -317,7 +317,7 @@ func worldStopped() { // //go:nosplit func worldStarted() { - if stopped := atomic.Xadd(&worldIsStopped, -1); stopped != 0 { + if stopped := worldIsStopped.Add(-1); stopped != 0 { systemstack(func() { print("world stop count=", stopped, "\n") throw("released non-stopped world stop") @@ -329,7 +329,7 @@ func worldStarted() { // //go:nosplit func checkWorldStopped() bool { - stopped := atomic.Load(&worldIsStopped) + stopped := worldIsStopped.Load() if stopped > 1 { systemstack(func() { print("inconsistent world stop count=", stopped, "\n") -- 2.48.1