Skip to content

Commit

Permalink
runtime: use correct state machine in addAdjustedTimers
Browse files Browse the repository at this point in the history
The addAdjustedTimers function was a late addition, and it got some of
the state machine wrong, leading to failures like
https://storage.googleapis.com/go-build-log/930576b6/windows-amd64-2016_53d0319e.log

Updates #6239
Updates #27707

Change-Id: I9e94e563b4698ff3035ce609055ca292b9cab3df
Reviewed-on: https://go-review.googlesource.com/c/go/+/204280
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
  • Loading branch information
ianlancetaylor committed Nov 1, 2019
1 parent efd395f commit e96fd13
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/runtime/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -989,10 +989,12 @@ func addAdjustedTimers(pp *p, moved []*timer) {
case timerDeleted:
// Timer has been deleted since we adjusted it.
// This timer is already out of the heap.
if !atomic.Cas(&t.status, s, timerRemoved) {
badTimer()
if atomic.Cas(&t.status, s, timerRemoving) {
if !atomic.Cas(&t.status, timerRemoving, timerRemoved) {
badTimer()
}
break loop
}
break loop
case timerModifiedEarlier, timerModifiedLater:
// Timer has been modified again since
// we adjusted it.
Expand All @@ -1007,8 +1009,8 @@ func addAdjustedTimers(pp *p, moved []*timer) {
if s == timerModifiedEarlier {
atomic.Xadd(&pp.adjustTimers, -1)
}
break loop
}
break loop
case timerNoStatus, timerRunning, timerRemoving, timerRemoved, timerMoving:
badTimer()
case timerModifying:
Expand Down

0 comments on commit e96fd13

Please sign in to comment.