]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: re-add call to ts.cleanHead (née cleantimers) during timer add
authorRuss Cox <rsc@golang.org>
Fri, 1 Mar 2024 00:08:59 +0000 (19:08 -0500)
committerGopher Robot <gobot@golang.org>
Fri, 8 Mar 2024 22:14:47 +0000 (22:14 +0000)
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 <iant@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/runtime/time.go

index f31ca3aeb718323b4bfe24a5eea92dc86b32896f..35dfff06d628c1726b1c135004f137516f1a0a81 100644 (file)
@@ -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
                }
        }