// The earliest known nextwhen field of a timer with
// timerModifiedEarlier status. Because the timer may have been
// modified again, there need not be any timer with this value.
- // This is updated using atomic functions.
// This is 0 if there are no timerModifiedEarlier timers.
- timerModifiedEarliest uint64
+ timerModifiedEarliest atomic.Uint64
// Per-P GC state
gcAssistTime int64 // Nanoseconds in assistAlloc
n := atomic.Xadd(&pp.numTimers, -1)
if n == 0 {
// If there are no timers, then clearly none are modified.
- atomic.Store64(&pp.timerModifiedEarliest, 0)
+ pp.timerModifiedEarliest.Store(0)
}
return smallestChanged
}
n := atomic.Xadd(&pp.numTimers, -1)
if n == 0 {
// If there are no timers, then clearly none are modified.
- atomic.Store64(&pp.timerModifiedEarliest, 0)
+ pp.timerModifiedEarliest.Store(0)
}
}
// a lot of timers back and forth if the timers rarely expire.
// We'll postpone looking through all the adjusted timers until
// one would actually expire.
- first := atomic.Load64(&pp.timerModifiedEarliest)
+ first := pp.timerModifiedEarliest.Load()
if first == 0 || int64(first) > now {
if verifyTimers {
verifyTimerHeap(pp)
}
// We are going to clear all timerModifiedEarlier timers.
- atomic.Store64(&pp.timerModifiedEarliest, 0)
+ pp.timerModifiedEarliest.Store(0)
var moved []*timer
for i := 0; i < len(pp.timers); i++ {
//go:nowritebarrierrec
func nobarrierWakeTime(pp *p) int64 {
next := int64(pp.timer0When.Load())
- nextAdj := int64(atomic.Load64(&pp.timerModifiedEarliest))
+ nextAdj := int64(pp.timerModifiedEarliest.Load())
if next == 0 || (nextAdj != 0 && nextAdj < next) {
next = nextAdj
}
func clearDeletedTimers(pp *p) {
// We are going to clear all timerModifiedEarlier timers.
// Do this now in case new ones show up while we are looping.
- atomic.Store64(&pp.timerModifiedEarliest, 0)
+ pp.timerModifiedEarliest.Store(0)
cdel := int32(0)
to := 0
// The timers for pp will not be locked.
func updateTimerModifiedEarliest(pp *p, nextwhen int64) {
for {
- old := atomic.Load64(&pp.timerModifiedEarliest)
+ old := pp.timerModifiedEarliest.Load()
if old != 0 && int64(old) < nextwhen {
return
}
- if atomic.Cas64(&pp.timerModifiedEarliest, old, uint64(nextwhen)) {
+
+ if pp.timerModifiedEarliest.CompareAndSwap(old, uint64(nextwhen)) {
return
}
}
next = w
}
- w = int64(atomic.Load64(&pp.timerModifiedEarliest))
+ w = int64(pp.timerModifiedEarliest.Load())
if w != 0 && w < next {
next = w
}