From: Russ Cox Date: Fri, 1 Mar 2024 00:08:59 +0000 (-0500) Subject: runtime: re-add call to ts.cleanHead (née cleantimers) during timer add X-Git-Tag: go1.23rc1~943 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7381123235ec13b596633c81bd9d84342e387e10;p=gostls13.git runtime: re-add call to ts.cleanHead (née cleantimers) during timer add Before CL 564118, there were two ways to add a new timer: addtimer or modtimer. Much code was duplicated between them and it was always valid to call modtimer instead of addtimer (but not vice versa), so that CL changed all addtimer call sites to use modtimer and deleted addtimer. One thing that was unique to addtimer, however, was that it called cleantimers (now named ts.cleanHead) after locking the timers, while modtimer did not. This was the only difference in the duplicated code, and I missed it. Restore the call to ts.cleanHead when adding a new timer. Also fix double-unlock in cleanHead. Change-Id: I26cc50d650f31f977c0c31195cd013244883dba9 Reviewed-on: https://go-review.googlesource.com/c/go/+/568338 Reviewed-by: Ian Lance Taylor Auto-Submit: Russ Cox LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Pratt --- diff --git a/src/runtime/time.go b/src/runtime/time.go index f31ca3aeb7..35dfff06d6 100644 --- a/src/runtime/time.go +++ b/src/runtime/time.go @@ -469,6 +469,7 @@ func (t *timer) needsAdd(state uint32) bool { func (t *timer) maybeAdd() { ts := &getg().m.p.ptr().timers ts.lock() + ts.cleanHead() state, mp := t.lock() when := int64(0) if t.needsAdd(state) { @@ -525,7 +526,6 @@ func (ts *timers) cleanHead() { t.unlock(state, mp) if !updated { // Head of timers does not need adjustment. - t.unlock(state, mp) return } }