From 402ea9e4f9ddcd2ed595ac12ce1b4e39f82e128f Mon Sep 17 00:00:00 2001 From: Changkun Ou Date: Mon, 3 Feb 2020 14:42:32 +0100 Subject: time: add Ticker.Reset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL implements Ticker.Reset method in time package. Benchmark: name time/op TickerReset-12 6.41µs ±10% TickerResetNaive-12 95.7µs ±12% Fixes #33184 Change-Id: I4cbd31796efa012b2a297bb342158f11a4a31fef Reviewed-on: https://go-review.googlesource.com/c/go/+/220424 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/runtime/time.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/runtime') diff --git a/src/runtime/time.go b/src/runtime/time.go index af5db4cc58..9e1129537a 100644 --- a/src/runtime/time.go +++ b/src/runtime/time.go @@ -233,6 +233,12 @@ func resetTimer(t *timer, when int64) { resettimer(t, when) } +// modTimer modifies an existing timer. +//go:linkname modTimer time.modTimer +func modTimer(t *timer, when, period int64, f func(interface{}, uintptr), arg interface{}, seq uintptr) { + modtimer(t, when, period, f, arg, seq) +} + // Go runtime. // Ready the goroutine arg. @@ -402,7 +408,7 @@ func dodeltimer0(pp *p) bool { } // modtimer modifies an existing timer. -// This is called by the netpoll code. +// This is called by the netpoll code or time.Ticker.Reset. func modtimer(t *timer, when, period int64, f func(interface{}, uintptr), arg interface{}, seq uintptr) { if when < 0 { when = maxWhen -- cgit v1.3