]> Cypherpunks.ru repositories - gostls13.git/commitdiff
runtime: convert forcegcstate.idle to internal atomic type
authorAndy Pan <panjf2000@gmail.com>
Wed, 24 Aug 2022 19:03:35 +0000 (03:03 +0800)
committerMichael Pratt <mpratt@google.com>
Fri, 26 Aug 2022 16:35:29 +0000 (16:35 +0000)
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>
src/runtime/proc.go
src/runtime/runtime2.go

index 3038b9819d0391ec8c68cbc367ff781daac4a226..b72e8b4d19eb4e5ac3032bae644792e78b97b788 100644 (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)
index 19ccfcea0eed549b057e356a41e7bde0340ad348..88e93a315f3e32ae0cf32f05cbcca2ba517ffd32 100644 (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.