diff options
| author | Russ Cox <rsc@golang.org> | 2024-02-14 11:57:03 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2024-02-28 16:44:13 +0000 |
| commit | 1df6db8e4fe0c8adf72e8533a09b46cad176eb42 (patch) | |
| tree | 52ed6cc657dd20b78278235551715e904ff98ce0 /src/runtime/time.go | |
| parent | d1e8dc25ff36694b5fdc8045325502e186b702f2 (diff) | |
| download | go-1df6db8e4fe0c8adf72e8533a09b46cad176eb42.tar.xz | |
runtime: use timer.lock in adjusttimers
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: I2298cede902cbf0aea268c54d741190007a733c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/564128
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime/time.go')
| -rw-r--r-- | src/runtime/time.go | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/src/runtime/time.go b/src/runtime/time.go index f94ad99196..251fe8eb49 100644 --- a/src/runtime/time.go +++ b/src/runtime/time.go @@ -521,21 +521,19 @@ func adjusttimers(pp *p, now int64, force bool) { if t.pp.ptr() != pp { throw("adjusttimers: bad p") } - switch s := t.status.Load(); s { - case timerModified: - if !t.status.CompareAndSwap(s, timerLocked) { - // TODO(rsc): Try harder to lock. - break - } + + status, mp := t.lock() + if status == timerRemoved { + badTimer() + } + if status == timerModified { if t.nextwhen == 0 { n := len(pp.timers) pp.timers[i] = pp.timers[n-1] pp.timers[n-1] = nil pp.timers = pp.timers[:n-1] t.pp = 0 - if !t.status.CompareAndSwap(timerLocked, timerRemoved) { - badTimer() - } + status = timerRemoved pp.deletedTimers.Add(-1) i-- changed = true @@ -543,21 +541,10 @@ func adjusttimers(pp *p, now int64, force bool) { // Now we can change the when field. t.when = t.nextwhen changed = true - if !t.status.CompareAndSwap(timerLocked, timerWaiting) { - badTimer() - } + status = timerWaiting } - case timerRemoved: - badTimer() - case timerWaiting: - // OK, nothing to do. - case timerLocked: - // Check again after modification is complete. - osyield() - i-- - default: - badTimer() } + t.unlock(status, mp) } if changed { |
