]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: convert profbuf.overflow to atomic type
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 17 Aug 2022 10:42:49 +0000 (17:42 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Thu, 18 Aug 2022 02:51:15 +0000 (02:51 +0000)
Updates #53821

Change-Id: Ib9c3be3d25c836636a59fdfacc63ba75edd9e016
Reviewed-on: https://go-review.googlesource.com/c/go/+/423889
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
src/runtime/profbuf.go

index 3d907d56124fa3b93dda251a61bd786faa0ff889..5e710812fb4f7a516cd7a2f1fb750faa47b0ce29 100644 (file)
@@ -87,7 +87,7 @@ import (
 type profBuf struct {
        // accessed atomically
        r, w         profAtomic
-       overflow     uint64
+       overflow     atomic.Uint64
        overflowTime uint64
        eof          uint32
 
@@ -150,14 +150,14 @@ func (x profIndex) addCountsAndClearFlags(data, tag int) profIndex {
 
 // hasOverflow reports whether b has any overflow records pending.
 func (b *profBuf) hasOverflow() bool {
-       return uint32(atomic.Load64(&b.overflow)) > 0
+       return uint32(b.overflow.Load()) > 0
 }
 
 // takeOverflow consumes the pending overflow records, returning the overflow count
 // and the time of the first overflow.
 // When called by the reader, it is racing against incrementOverflow.
 func (b *profBuf) takeOverflow() (count uint32, time uint64) {
-       overflow := atomic.Load64(&b.overflow)
+       overflow := b.overflow.Load()
        time = atomic.Load64(&b.overflowTime)
        for {
                count = uint32(overflow)
@@ -166,10 +166,10 @@ func (b *profBuf) takeOverflow() (count uint32, time uint64) {
                        break
                }
                // Increment generation, clear overflow count in low bits.
-               if atomic.Cas64(&b.overflow, overflow, ((overflow>>32)+1)<<32) {
+               if b.overflow.CompareAndSwap(overflow, ((overflow>>32)+1)<<32) {
                        break
                }
-               overflow = atomic.Load64(&b.overflow)
+               overflow = b.overflow.Load()
                time = atomic.Load64(&b.overflowTime)
        }
        return uint32(overflow), time
@@ -179,14 +179,14 @@ func (b *profBuf) takeOverflow() (count uint32, time uint64) {
 // It is racing against a possible takeOverflow in the reader.
 func (b *profBuf) incrementOverflow(now int64) {
        for {
-               overflow := atomic.Load64(&b.overflow)
+               overflow := b.overflow.Load()
 
                // Once we see b.overflow reach 0, it's stable: no one else is changing it underfoot.
                // We need to set overflowTime if we're incrementing b.overflow from 0.
                if uint32(overflow) == 0 {
                        // Store overflowTime first so it's always available when overflow != 0.
                        atomic.Store64(&b.overflowTime, uint64(now))
-                       atomic.Store64(&b.overflow, (((overflow>>32)+1)<<32)+1)
+                       b.overflow.Store((((overflow >> 32) + 1) << 32) + 1)
                        break
                }
                // Otherwise we're racing to increment against reader
@@ -196,7 +196,7 @@ func (b *profBuf) incrementOverflow(now int64) {
                if int32(overflow) == -1 {
                        break
                }
-               if atomic.Cas64(&b.overflow, overflow, overflow+1) {
+               if b.overflow.CompareAndSwap(overflow, overflow+1) {
                        break
                }
        }