From e0ec1d6770879518af726b6cd8693dab3390db24 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Thu, 25 Aug 2022 03:03:35 +0800 Subject: [PATCH] runtime: convert forcegcstate.idle to internal atomic type Note that this changes a few unsynchronized operations of forcegcstate.idle to synchronized operations. Updates #53821 Change-Id: I041654cc84a188fad45e2df7abce3a434f9a1f15 Reviewed-on: https://go-review.googlesource.com/c/go/+/425361 Reviewed-by: Michael Knyszek Reviewed-by: Michael Pratt --- src/runtime/proc.go | 8 ++++---- src/runtime/runtime2.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 3038b9819d..b72e8b4d19 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -295,10 +295,10 @@ func forcegchelper() { lockInit(&forcegc.lock, lockRankForcegc) for { lock(&forcegc.lock) - if forcegc.idle != 0 { + if forcegc.idle.Load() { throw("forcegc: phase error") } - atomic.Store(&forcegc.idle, 1) + forcegc.idle.Store(true) goparkunlock(&forcegc.lock, waitReasonForceGCIdle, traceEvGoBlock, 1) // this goroutine is explicitly resumed by sysmon if debug.gctrace > 0 { @@ -5312,9 +5312,9 @@ func sysmon() { idle++ } // check if we need to force a GC - if t := (gcTrigger{kind: gcTriggerTime, now: now}); t.test() && atomic.Load(&forcegc.idle) != 0 { + if t := (gcTrigger{kind: gcTriggerTime, now: now}); t.test() && forcegc.idle.Load() { lock(&forcegc.lock) - forcegc.idle = 0 + forcegc.idle.Store(false) var list gList list.push(forcegc.g) injectglist(&list) diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index 19ccfcea0e..88e93a315f 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -912,7 +912,7 @@ type lfnode struct { type forcegcstate struct { lock mutex g *g - idle uint32 + idle atomic.Bool } // extendRandom extends the random numbers in r[:n] to the whole slice r. -- 2.50.0