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

runtime: convert p.timer0When to atomic type

Updates #53821

Change-Id: I523ec61116d290ecf7b7e3eb96e468695766cb4d
Reviewed-on: https://go-review.googlesource.com/c/go/+/424396
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Cuong Manh Le 2022-08-17 14:56:18 +07:00 committed by Gopher Robot
parent bc805795bd
commit e1fd51e076
3 changed files with 8 additions and 9 deletions

View File

@ -3329,7 +3329,7 @@ func dropg() {
func checkTimers(pp *p, now int64) (rnow, pollUntil int64, ran bool) {
// If it's not yet time for the first timer, or the first adjusted
// timer, then there is nothing to do.
next := int64(atomic.Load64(&pp.timer0When))
next := int64(pp.timer0When.Load())
nextAdj := int64(atomic.Load64(&pp.timerModifiedEarliest))
if next == 0 || (nextAdj != 0 && nextAdj < next) {
next = nextAdj
@ -4787,7 +4787,7 @@ func (pp *p) destroy() {
pp.timers = nil
pp.numTimers = 0
pp.deletedTimers = 0
atomic.Store64(&pp.timer0When, 0)
pp.timer0When.Store(0)
unlock(&pp.timersLock)
unlock(&plocal.timersLock)
}

View File

@ -670,9 +670,8 @@ type p struct {
_ uint32 // Alignment for atomic fields below
// The when field of the first entry on the timer heap.
// This is updated using atomic functions.
// This is 0 if the timer heap is empty.
timer0When uint64
timer0When atomic.Uint64
// The earliest known nextwhen field of a timer with
// timerModifiedEarlier status. Because the timer may have been

View File

@ -301,7 +301,7 @@ func doaddtimer(pp *p, t *timer) {
pp.timers = append(pp.timers, t)
siftupTimer(pp.timers, i)
if t == pp.timers[0] {
atomic.Store64(&pp.timer0When, uint64(t.when))
pp.timer0When.Store(uint64(t.when))
}
atomic.Xadd(&pp.numTimers, 1)
}
@ -754,7 +754,7 @@ func addAdjustedTimers(pp *p, moved []*timer) {
//
//go:nowritebarrierrec
func nobarrierWakeTime(pp *p) int64 {
next := int64(atomic.Load64(&pp.timer0When))
next := int64(pp.timer0When.Load())
nextAdj := int64(atomic.Load64(&pp.timerModifiedEarliest))
if next == 0 || (nextAdj != 0 && nextAdj < next) {
next = nextAdj
@ -1003,9 +1003,9 @@ func verifyTimerHeap(pp *p) {
// The caller must have locked the timers for pp.
func updateTimer0When(pp *p) {
if len(pp.timers) == 0 {
atomic.Store64(&pp.timer0When, 0)
pp.timer0When.Store(0)
} else {
atomic.Store64(&pp.timer0When, uint64(pp.timers[0].when))
pp.timer0When.Store(uint64(pp.timers[0].when))
}
}
@ -1039,7 +1039,7 @@ func timeSleepUntil() int64 {
continue
}
w := int64(atomic.Load64(&pp.timer0When))
w := int64(pp.timer0When.Load())
if w != 0 && w < next {
next = w
}