1
0
mirror of https://github.com/golang/go synced 2024-11-26 17:16:54 -07:00

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 <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
Andy Pan 2022-08-25 03:03:35 +08:00 committed by Michael Pratt
parent 951d2c657d
commit e0ec1d6770
2 changed files with 5 additions and 5 deletions

View File

@ -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)

View File

@ -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.