diff options
| author | Russ Cox <rsc@golang.org> | 2024-02-14 11:57:01 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2024-02-28 16:44:09 +0000 |
| commit | 58911599e8dc25898c3017dd6655540fb9b976b1 (patch) | |
| tree | 0d609a29b7b08006762671f4d45f01c6daeae8c5 /src/runtime | |
| parent | 2fb5ef889bf86dfb25880cf087a3e02f7100df29 (diff) | |
| download | go-58911599e8dc25898c3017dd6655540fb9b976b1.tar.xz | |
runtime: use timer.lock in cleantimers
Continue using timer.lock to simplify timer operations.
[This is one CL in a refactoring stack making very small changes
in each step, so that any subtle bugs that we miss can be more
easily pinpointed to a small change.]
Change-Id: Ic12fd2630e8ac23cddd00fa7e3240a1ac19da596
Reviewed-on: https://go-review.googlesource.com/c/go/+/564126
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/time.go | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/runtime/time.go b/src/runtime/time.go index 5a8f516cca..2b82306812 100644 --- a/src/runtime/time.go +++ b/src/runtime/time.go @@ -393,31 +393,31 @@ func cleantimers(pp *p) { if t.pp.ptr() != pp { throw("cleantimers: bad p") } - switch s := t.status.Load(); s { - case timerModified: - if !t.status.CompareAndSwap(s, timerLocked) { - continue - } - if t.nextwhen == 0 { - dodeltimer0(pp) - pp.deletedTimers.Add(-1) - if !t.status.CompareAndSwap(timerLocked, timerRemoved) { - badTimer() - } - } else { - // Now we can change the when field. - t.when = t.nextwhen - // Move t to the right position. - dodeltimer0(pp) - doaddtimer(pp, t) - if !t.status.CompareAndSwap(timerLocked, timerWaiting) { - badTimer() - } - } - default: + + status := t.status.Load() + if status != timerModified { + // Fast path: head of timers does not need adjustment. + return + } + + status, mp := t.lock() + if status != timerModified { // Head of timers does not need adjustment. + t.unlock(status, mp) return } + dodeltimer0(pp) + if t.nextwhen == 0 { + pp.deletedTimers.Add(-1) + status = timerRemoved + } else { + // Now we can change the when field. + t.when = t.nextwhen + // Move t to the right position. + doaddtimer(pp, t) + status = timerWaiting + } + t.unlock(status, mp) } } |
