]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert consistentHeapStats.gen to atomic type
authorcuiweixie <cuiweixie@gmail.com>
Fri, 26 Aug 2022 03:24:39 +0000 (11:24 +0800)
committerMichael Pratt <mpratt@google.com>
Wed, 31 Aug 2022 21:10:41 +0000 (21:10 +0000)
For #53821

Change-Id: I9f57b84f6a2c29d750fb20420daef903a9311a83
Reviewed-on: https://go-review.googlesource.com/c/go/+/425781
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/runtime/mstats.go

index 70c5a703e7d0935904f47b3f4d994810fd016bd5..d4ef933611158b125d2c0b0bd544c625c0e50aa4 100644 (file)
@@ -727,8 +727,7 @@ type consistentHeapStats struct {
 
        // gen represents the current index into which writers
        // are writing, and can take on the value of 0, 1, or 2.
-       // This value is updated atomically.
-       gen uint32
+       gen atomic.Uint32
 
        // noPLock is intended to provide mutual exclusion for updating
        // stats when no P is available. It does not block other writers
@@ -766,7 +765,7 @@ func (m *consistentHeapStats) acquire() *heapStatsDelta {
        } else {
                lock(&m.noPLock)
        }
-       gen := atomic.Load(&m.gen) % 3
+       gen := m.gen.Load() % 3
        return &m.stats[gen]
 }
 
@@ -837,7 +836,7 @@ func (m *consistentHeapStats) read(out *heapStatsDelta) {
        // Get the current generation. We can be confident that this
        // will not change since read is serialized and is the only
        // one that modifies currGen.
-       currGen := atomic.Load(&m.gen)
+       currGen := m.gen.Load()
        prevGen := currGen - 1
        if currGen == 0 {
                prevGen = 2
@@ -852,7 +851,7 @@ func (m *consistentHeapStats) read(out *heapStatsDelta) {
        //
        // This exchange is safe to do because we won't race
        // with anyone else trying to update this value.
-       atomic.Xchg(&m.gen, (currGen+1)%3)
+       m.gen.Swap((currGen + 1) % 3)
 
        // Allow P-less writers to continue. They'll be writing to the
        // next generation now.