]> Cypherpunks repositories - gostls13.git/commit
runtime: clean up timer state
authorRuss Cox <rsc@golang.org>
Sat, 9 Mar 2024 18:36:58 +0000 (13:36 -0500)
committerGopher Robot <gobot@golang.org>
Wed, 13 Mar 2024 17:06:22 +0000 (17:06 +0000)
commit613565186792ecee69ed6d43e7290c6124e81f33
tree7b024b074350454ecec1acfb3fb9f8d8e252b766
parentb2e9221089f37400f309637b205f21af7dcb063b
runtime: clean up timer state

The timers had evolved to the point where the state was stored as follows:

if timer in heap:
    state has timerHeaped set
    if heap timer is stale:
        heap deadline in t.when
        real deadline in t.nextWhen
        state has timerNextWhen set
    else:
        real deadline in t.when
        t.nextWhen unset
else:
    real deadline in t.when
    t.nextWhen unset

That made it hard to find the real deadline and just hard to think about everything.
The new state is:

real deadline in t.when (always)
if timer in heap:
    state has timerHeaped set
    heap deadline in t.whenHeap
    if heap timer is stale:
        state has timerModified set

Separately, the 'state' word itself was being used as a lock
and state bits because the code started with CAS loops,
which we abstracted into the lock/unlock methods step by step.
At this point, we can switch to a real lock, making sure to
publish the one boolean needed by timers fast paths
at each unlock.

All this simplifies various logic considerably.

Change-Id: I35766204f7a26d999206bd56cc0db60ad1b17cbe
Reviewed-on: https://go-review.googlesource.com/c/go/+/570335
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/runtime/mgcscavenge.go
src/runtime/netpoll.go
src/runtime/runtime2.go
src/runtime/sizeof_test.go
src/runtime/time.go
src/runtime/trace2.go
src/time/sleep.go
src/time/tick.go