@@ -33,6 +33,7 @@ type timer struct {
33
33
// isSending is used to handle races between running a
34
34
// channel timer and stopping or resetting the timer.
35
35
// It is used only for channel timers (t.isChan == true).
36
+ // It is not used for tickers.
36
37
// The lowest zero bit is set when about to send a value on the channel,
37
38
// and cleared after sending the value.
38
39
// The stop/reset code uses this to detect whether it
@@ -467,7 +468,7 @@ func (t *timer) stop() bool {
467
468
// send from actually happening. That means
468
469
// that we should return true: the timer was
469
470
// stopped, even though t.when may be zero.
470
- if t .isSending .Load () > 0 {
471
+ if t .period == 0 && t . isSending .Load () > 0 {
471
472
pending = true
472
473
}
473
474
}
@@ -529,6 +530,7 @@ func (t *timer) modify(when, period int64, f func(arg any, seq uintptr, delay in
529
530
t .maybeRunAsync ()
530
531
}
531
532
t .trace ("modify" )
533
+ oldPeriod := t .period
532
534
t .period = period
533
535
if f != nil {
534
536
t .f = f
@@ -570,7 +572,7 @@ func (t *timer) modify(when, period int64, f func(arg any, seq uintptr, delay in
570
572
// send from actually happening. That means
571
573
// that we should return true: the timer was
572
574
// stopped, even though t.when may be zero.
573
- if t .isSending .Load () > 0 {
575
+ if oldPeriod == 0 && t .isSending .Load () > 0 {
574
576
pending = true
575
577
}
576
578
}
@@ -1064,7 +1066,7 @@ func (t *timer) unlockAndRun(now int64) {
1064
1066
1065
1067
async := debug .asynctimerchan .Load () != 0
1066
1068
var isSendingClear uint8
1067
- if ! async && t .isChan {
1069
+ if ! async && t .isChan && t . period == 0 {
1068
1070
// Tell Stop/Reset that we are sending a value.
1069
1071
// Set the lowest zero bit.
1070
1072
// We do this awkward step because atomic.Uint8
@@ -1115,9 +1117,12 @@ func (t *timer) unlockAndRun(now int64) {
1115
1117
// true meaning that no value was sent.
1116
1118
lock (& t .sendLock )
1117
1119
1118
- // We are committed to possibly sending a value based on seq,
1119
- // so no need to keep telling stop/modify that we are sending.
1120
- t .isSending .And (^ isSendingClear )
1120
+ if t .period == 0 {
1121
+ // We are committed to possibly sending a value
1122
+ // based on seq, so no need to keep telling
1123
+ // stop/modify that we are sending.
1124
+ t .isSending .And (^ isSendingClear )
1125
+ }
1121
1126
1122
1127
if t .seq != seq {
1123
1128
f = func (any , uintptr , int64 ) {}
0 commit comments