// resetTimer resets an inactive timer, adding it to the heap.
//go:linkname resetTimer time.resetTimer
-func resetTimer(t *timer, when int64) {
+// Reports whether the timer was modified before it was run.
+func resetTimer(t *timer, when int64) bool {
if raceenabled {
racerelease(unsafe.Pointer(t))
}
- resettimer(t, when)
+ return resettimer(t, when)
}
// modTimer modifies an existing timer.
// modtimer modifies an existing timer.
// 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) {
+// Reports whether the timer was modified before it was run.
+func modtimer(t *timer, when, period int64, f func(interface{}, uintptr), arg interface{}, seq uintptr) bool {
if when < 0 {
when = maxWhen
}
status := uint32(timerNoStatus)
wasRemoved := false
+ var pending bool
var mp *m
loop:
for {
// This could lead to a self-deadlock. See #38070.
mp = acquirem()
if atomic.Cas(&t.status, status, timerModifying) {
+ pending = true // timer not yet run
break loop
}
releasem(mp)
// Act like addtimer.
if atomic.Cas(&t.status, status, timerModifying) {
wasRemoved = true
+ pending = false // timer already run or stopped
break loop
}
releasem(mp)
mp = acquirem()
if atomic.Cas(&t.status, status, timerModifying) {
atomic.Xadd(&t.pp.ptr().deletedTimers, -1)
+ pending = false // timer already stopped
break loop
}
releasem(mp)
wakeNetPoller(when)
}
}
+
+ return pending
}
// resettimer resets the time when a timer should fire.
// If used for an inactive timer, the timer will become active.
// 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) {
- modtimer(t, when, t.period, t.f, t.arg, t.seq)
+// Reports whether the timer was modified before it was run.
+func resettimer(t *timer, when int64) bool {
+ return modtimer(t, when, t.period, t.f, t.arg, t.seq)
}
// cleantimers cleans up the head of the timer queue. This speeds up
func startTimer(*runtimeTimer)
func stopTimer(*runtimeTimer) bool
-func resetTimer(*runtimeTimer, int64)
+func resetTimer(*runtimeTimer, int64) bool
func modTimer(t *runtimeTimer, when, period int64, f func(interface{}, uintptr), arg interface{}, seq uintptr)
// The Timer type represents a single event.
panic("time: Reset called on uninitialized Timer")
}
w := when(d)
- active := stopTimer(&t.r)
- resetTimer(&t.r, w)
- return active
+ return resetTimer(&t.r, w)
}
func sendTime(c interface{}, seq uintptr) {