From 7381123235ec13b596633c81bd9d84342e387e10 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 29 Feb 2024 19:08:59 -0500 Subject: [PATCH] =?utf8?q?runtime:=20re-add=20call=20to=20ts.cleanHead=20(?= =?utf8?q?n=C3=A9e=20cleantimers)=20during=20timer=20add?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- src/runtime/time.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } } -- 2.48.1