// because we can't close over any variables without
// failing escape analysis.
now := nanotime()
- scavenge.timer.when = now + ns
- startTimer(scavenge.timer)
+ resetTimer(scavenge.timer, now+ns)
// Mark ourself as asleep and go to sleep.
scavenge.parked = true
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
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
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.
}
}
+// 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.
// once more.
stopTimer(r)
t.Stop()
- r.when = 0
- startTimer(r)
+ resetTimer(r, 0)
}()
// If the test fails, we will hang here until the timeout in the testing package
func startTimer(*runtimeTimer)
func stopTimer(*runtimeTimer) bool
+func resetTimer(*runtimeTimer, int64)
// The Timer type represents a single event.
// When the Timer expires, the current time will be sent on C,
}
w := when(d)
active := stopTimer(&t.r)
- t.r.when = w
- startTimer(&t.r)
+ resetTimer(&t.r, w)
return active
}