From a7ce2ca52f6de38e7db0a67bbdf697a6b5dc122a Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 10 Apr 2019 17:23:05 -0700 Subject: 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 TryBot-Result: Gobot Gobot Reviewed-by: Michael Knyszek Reviewed-by: Emmanuel Odeke --- src/runtime/netpoll.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/runtime/netpoll.go') diff --git a/src/runtime/netpoll.go b/src/runtime/netpoll.go index 7d18dcaeea..536dae3d4f 100644 --- a/src/runtime/netpoll.go +++ b/src/runtime/netpoll.go @@ -239,13 +239,12 @@ func poll_runtime_pollSetDeadline(pd *pollDesc, d int64, mode int) { if pd.rt.f == nil { if pd.rd > 0 { pd.rt.f = rtf - pd.rt.when = pd.rd // Copy current seq into the timer arg. // Timer func will check the seq against current descriptor seq, // if they differ the descriptor was reused or timers were reset. pd.rt.arg = pd pd.rt.seq = pd.rseq - addtimer(&pd.rt) + resettimer(&pd.rt, pd.rd) } } else if pd.rd != rd0 || combo != combo0 { pd.rseq++ // invalidate current timers @@ -259,10 +258,9 @@ func poll_runtime_pollSetDeadline(pd *pollDesc, d int64, mode int) { if pd.wt.f == nil { if pd.wd > 0 && !combo { pd.wt.f = netpollWriteDeadline - pd.wt.when = pd.wd pd.wt.arg = pd pd.wt.seq = pd.wseq - addtimer(&pd.wt) + resettimer(&pd.wt, pd.wd) } } else if pd.wd != wd0 || combo != combo0 { pd.wseq++ // invalidate current timers -- cgit v1.3-5-g9baa