// if we would clear deleted timers.
// This corresponds to the condition below where
// we decide whether to call clearDeletedTimers.
- if pp != getg().m.p.ptr() || int(atomic.Load(&pp.deletedTimers)) <= int(atomic.Load(&pp.numTimers)/4) {
+ if pp != getg().m.p.ptr() || int(pp.deletedTimers.Load()) <= int(pp.numTimers.Load()/4) {
return now, next, false
}
}
// If this is the local P, and there are a lot of deleted timers,
// clear them out. We only do this for the local P to reduce
// lock contention on timersLock.
- if pp == getg().m.p.ptr() && int(atomic.Load(&pp.deletedTimers)) > len(pp.timers)/4 {
+ if pp == getg().m.p.ptr() && int(pp.deletedTimers.Load()) > len(pp.timers)/4 {
clearDeletedTimers(pp)
}
lock(&pp.timersLock)
moveTimers(plocal, pp.timers)
pp.timers = nil
- pp.numTimers = 0
- pp.deletedTimers = 0
+ pp.numTimers.Store(0)
+ pp.deletedTimers.Store(0)
pp.timer0When.Store(0)
unlock(&pp.timersLock)
unlock(&plocal.timersLock)
// TODO(prattmic): Additional targeted updates may improve the above cases.
// e.g., updating the mask when stealing a timer.
func updateTimerPMask(pp *p) {
- if atomic.Load(&pp.numTimers) > 0 {
+ if pp.numTimers.Load() > 0 {
return
}
// decrement numTimers when handling a timerModified timer in
// checkTimers. We must take timersLock to serialize with these changes.
lock(&pp.timersLock)
- if atomic.Load(&pp.numTimers) == 0 {
+ if pp.numTimers.Load() == 0 {
timerpMask.clear(pp.id)
}
unlock(&pp.timersLock)
if t == pp.timers[0] {
pp.timer0When.Store(t.when)
}
- atomic.Xadd(&pp.numTimers, 1)
+ pp.numTimers.Add(1)
}
// deltimer deletes the timer t. It may be on some other P, so we can't
badTimer()
}
releasem(mp)
- atomic.Xadd(&tpp.deletedTimers, 1)
+ tpp.deletedTimers.Add(1)
// Timer was not yet run.
return true
} else {
badTimer()
}
releasem(mp)
- atomic.Xadd(&tpp.deletedTimers, 1)
+ tpp.deletedTimers.Add(1)
// Timer was not yet run.
return true
} else {
if i == 0 {
updateTimer0When(pp)
}
- n := atomic.Xadd(&pp.numTimers, -1)
+ n := pp.numTimers.Add(-1)
if n == 0 {
// If there are no timers, then clearly none are modified.
pp.timerModifiedEarliest.Store(0)
siftdownTimer(pp.timers, 0)
}
updateTimer0When(pp)
- n := atomic.Xadd(&pp.numTimers, -1)
+ n := pp.numTimers.Add(-1)
if n == 0 {
// If there are no timers, then clearly none are modified.
pp.timerModifiedEarliest.Store(0)
// This could lead to a self-deadlock. See #38070.
mp = acquirem()
if atomic.Cas(&t.status, status, timerModifying) {
- atomic.Xadd(&t.pp.ptr().deletedTimers, -1)
+ t.pp.ptr().deletedTimers.Add(-1)
pending = false // timer already stopped
break loop
}
if !atomic.Cas(&t.status, timerRemoving, timerRemoved) {
badTimer()
}
- atomic.Xadd(&pp.deletedTimers, -1)
+ pp.deletedTimers.Add(-1)
case timerModifiedEarlier, timerModifiedLater:
if !atomic.Cas(&t.status, s, timerMoving) {
continue
if !atomic.Cas(&t.status, timerRemoving, timerRemoved) {
badTimer()
}
- atomic.Xadd(&pp.deletedTimers, -1)
+ pp.deletedTimers.Add(-1)
// Go back to the earliest changed heap entry.
// "- 1" because the loop will add 1.
i = changed - 1
if !atomic.Cas(&t.status, timerRemoving, timerRemoved) {
badTimer()
}
- atomic.Xadd(&pp.deletedTimers, -1)
+ pp.deletedTimers.Add(-1)
if len(pp.timers) == 0 {
return -1
}
timers[i] = nil
}
- atomic.Xadd(&pp.deletedTimers, -cdel)
- atomic.Xadd(&pp.numTimers, -cdel)
+ pp.deletedTimers.Add(-cdel)
+ pp.numTimers.Add(-cdel)
timers = timers[:to]
pp.timers = timers
throw("bad timer heap")
}
}
- if numTimers := int(atomic.Load(&pp.numTimers)); len(pp.timers) != numTimers {
+ if numTimers := int(pp.numTimers.Load()); len(pp.timers) != numTimers {
println("timer heap len", len(pp.timers), "!= numTimers", numTimers)
throw("bad timer heap len")
}