Skip to content

Commit 5ec81d7

Browse files
committed
ensure WakeG modifies the right timer
1 parent 6e56424 commit 5ec81d7

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/runtime/sys_tamago_arm.s

+20-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ TEXT runtime·WakeG(SB),NOSPLIT|NOFRAME,$0-0
176176
CMP $0, R2
177177
B.EQ done
178178

179-
// find longest timer offset
179+
// offset to last element
180180
SUB $1, R2, R2
181181
MOVW $(timerWhen__size), R3
182182
MUL R3, R2, R2
@@ -185,8 +185,26 @@ TEXT runtime·WakeG(SB),NOSPLIT|NOFRAME,$0-0
185185
CMP $0, R0
186186
B.EQ done
187187

188-
// g->timer.ts.heap[last].when = 1
188+
// g->timer.ts.heap[len-1]
189189
ADD R2, R0, R0
190+
B check
191+
192+
prev:
193+
SUB $(timerWhen__size), R0
194+
CMP $0, R0
195+
B.EQ done
196+
197+
check:
198+
// find longest timer as *timers.adjust() might be pending
199+
MOVW (timerWhen_when+0)(R0), R1
200+
CMP $0xffffffff, R1 // LS word of math.MaxInt64
201+
B.NE prev
202+
203+
MOVW (timerWhen_when+4)(R0), R1
204+
CMP $0x7fffffff, R1 // MS word of math.MaxInt64
205+
B.NE prev
206+
207+
// g->timer.ts.heap[off] = 1
190208
MOVW $1, R1
191209
MOVW R1, (timerWhen_when+0)(R0)
192210
MOVW $0, R1

src/runtime/sys_tamago_riscv64.s

+15-2
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,29 @@ TEXT runtime·WakeG(SB),NOSPLIT|NOFRAME,$0-0
9292
MOV (timers_heap+8)(T0), T2
9393
BEQ T2, ZERO, done
9494

95-
// find longest timer offset
95+
// offset to last element
9696
SUB $1, T2, T2
9797
MOV $(timerWhen__size), T3
9898
MUL T3, T2, T2
9999

100100
MOV (timers_heap)(T0), T0
101101
BEQ T0, ZERO, done
102102

103-
// g->timer.ts.heap[last].when = 1
103+
// g->timer.ts.heap[len-1]
104104
ADD T2, T0, T0
105+
JMP check
106+
107+
prev:
108+
SUB $(timerWhen__size), T0
109+
BEQ T0, ZERO, done
110+
111+
check:
112+
// find longest timer as *timers.adjust() might be pending
113+
MOV (timerWhen_when)(T0), T1
114+
MOV $((1 << 63) - 1), T2 // math.MaxInt64
115+
BNE T2, T1, prev
116+
117+
// g->timer.ts.heap[off] = 1
105118
MOV $(1 << 32), T1
106119
MOV T1, (timerWhen_when)(T0)
107120

0 commit comments

Comments
 (0)