mirror of https://github.com/golang/go.git
runtime: use timer.lock in adjusttimers
Continue using timer.lock to simplify timer operations. [This is one CL in a refactoring stack making very small changes in each step, so that any subtle bugs that we miss can be more easily pinpointed to a small change.] Change-Id: I2298cede902cbf0aea268c54d741190007a733c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/564128 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
d1e8dc25ff
commit
1df6db8e4f
|
|
@ -521,21 +521,19 @@ func adjusttimers(pp *p, now int64, force bool) {
|
||||||
if t.pp.ptr() != pp {
|
if t.pp.ptr() != pp {
|
||||||
throw("adjusttimers: bad p")
|
throw("adjusttimers: bad p")
|
||||||
}
|
}
|
||||||
switch s := t.status.Load(); s {
|
|
||||||
case timerModified:
|
status, mp := t.lock()
|
||||||
if !t.status.CompareAndSwap(s, timerLocked) {
|
if status == timerRemoved {
|
||||||
// TODO(rsc): Try harder to lock.
|
badTimer()
|
||||||
break
|
}
|
||||||
}
|
if status == timerModified {
|
||||||
if t.nextwhen == 0 {
|
if t.nextwhen == 0 {
|
||||||
n := len(pp.timers)
|
n := len(pp.timers)
|
||||||
pp.timers[i] = pp.timers[n-1]
|
pp.timers[i] = pp.timers[n-1]
|
||||||
pp.timers[n-1] = nil
|
pp.timers[n-1] = nil
|
||||||
pp.timers = pp.timers[:n-1]
|
pp.timers = pp.timers[:n-1]
|
||||||
t.pp = 0
|
t.pp = 0
|
||||||
if !t.status.CompareAndSwap(timerLocked, timerRemoved) {
|
status = timerRemoved
|
||||||
badTimer()
|
|
||||||
}
|
|
||||||
pp.deletedTimers.Add(-1)
|
pp.deletedTimers.Add(-1)
|
||||||
i--
|
i--
|
||||||
changed = true
|
changed = true
|
||||||
|
|
@ -543,21 +541,10 @@ func adjusttimers(pp *p, now int64, force bool) {
|
||||||
// Now we can change the when field.
|
// Now we can change the when field.
|
||||||
t.when = t.nextwhen
|
t.when = t.nextwhen
|
||||||
changed = true
|
changed = true
|
||||||
if !t.status.CompareAndSwap(timerLocked, timerWaiting) {
|
status = timerWaiting
|
||||||
badTimer()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case timerRemoved:
|
|
||||||
badTimer()
|
|
||||||
case timerWaiting:
|
|
||||||
// OK, nothing to do.
|
|
||||||
case timerLocked:
|
|
||||||
// Check again after modification is complete.
|
|
||||||
osyield()
|
|
||||||
i--
|
|
||||||
default:
|
|
||||||
badTimer()
|
|
||||||
}
|
}
|
||||||
|
t.unlock(status, mp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if changed {
|
if changed {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue