diff options
| author | Ian Lance Taylor <iant@golang.org> | 2019-04-10 17:23:05 -0700 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2019-10-21 17:06:22 +0000 |
| commit | a7ce2ca52f6de38e7db0a67bbdf697a6b5dc122a (patch) | |
| tree | 2cc39783637634d8d8df9f859e5ead005d68de64 /src/runtime/time.go | |
| parent | 7a6da218b191de13f4f3555c55aab958b09b66bd (diff) | |
| download | go-a7ce2ca52f6de38e7db0a67bbdf697a6b5dc122a.tar.xz | |
runtime, syscall, time: add and use resettimer
As a small step toward speeding up timers, restrict modification
of the timer.when field to the timer code itself. Other code that
wants to change the when field of an existing timer must now call
resettimer rather than changing the when field and calling addtimer.
The new resettimer function also works for a new timer.
This is just a refactoring in preparation for later code.
Updates #27707
Change-Id: Iccd5dcad415ffbeac4c2a3cf015e91f82692acf8
Reviewed-on: https://go-review.googlesource.com/c/go/+/171825
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Diffstat (limited to 'src/runtime/time.go')
| -rw-r--r-- | src/runtime/time.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/runtime/time.go b/src/runtime/time.go index d667d11244..5521b8a807 100644 --- a/src/runtime/time.go +++ b/src/runtime/time.go @@ -116,6 +116,15 @@ func stopTimer(t *timer) bool { return deltimer(t) } +// resetTimer resets an inactive timer, adding it to the heap. +//go:linkname resetTimer time.resetTimer +func resetTimer(t *timer, when int64) { + if raceenabled { + racerelease(unsafe.Pointer(t)) + } + resettimer(t, when) +} + // Go runtime. // Ready the goroutine arg. @@ -236,6 +245,15 @@ func modtimer(t *timer, when, period int64, f func(interface{}, uintptr), arg in } } +// resettimer resets an existing inactive timer to turn it into an active timer, +// with a new time for when the timer should fire. +// This should be called instead of addtimer if the timer value has been, +// or may have been, used previously. +func resettimer(t *timer, when int64) { + t.when = when + addtimer(t) +} + // Timerproc runs the time-driven events. // It sleeps until the next event in the tb heap. // If addtimer inserts a new earlier event, it wakes timerproc early. |
