Skip to content

Commit e96fd13

Browse files
runtime: use correct state machine in addAdjustedTimers
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 <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent efd395f commit e96fd13

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/runtime/time.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -989,10 +989,12 @@ func addAdjustedTimers(pp *p, moved []*timer) {
989989
case timerDeleted:
990990
// Timer has been deleted since we adjusted it.
991991
// This timer is already out of the heap.
992-
if !atomic.Cas(&t.status, s, timerRemoved) {
993-
badTimer()
992+
if atomic.Cas(&t.status, s, timerRemoving) {
993+
if !atomic.Cas(&t.status, timerRemoving, timerRemoved) {
994+
badTimer()
995+
}
996+
break loop
994997
}
995-
break loop
996998
case timerModifiedEarlier, timerModifiedLater:
997999
// Timer has been modified again since
9981000
// we adjusted it.
@@ -1007,8 +1009,8 @@ func addAdjustedTimers(pp *p, moved []*timer) {
10071009
if s == timerModifiedEarlier {
10081010
atomic.Xadd(&pp.adjustTimers, -1)
10091011
}
1012+
break loop
10101013
}
1011-
break loop
10121014
case timerNoStatus, timerRunning, timerRemoving, timerRemoved, timerMoving:
10131015
badTimer()
10141016
case timerModifying:

0 commit comments

Comments
 (0)