@@ -177,3 +177,76 @@ testing:
177
177
JLS 2 (PC)
178
178
MOVL $0xf1 , 0xf1 // crash
179
179
RET
180
+
181
+ // WakeG modifies a goroutine cached timer for time.Sleep (g.timer) to fire as
182
+ // soon as possible.
183
+ //
184
+ // The function arguments must be passed through the following registers
185
+ // (rather than on the frame pointer):
186
+ //
187
+ // * AX: G pointer
188
+ TEXT runtime·WakeG(SB),NOSPLIT|NOFRAME,$0 -0
189
+ MOVQ (g_timer)(AX), AX
190
+ CMPQ AX, $0
191
+ JE done
192
+
193
+ // g->timer.when = 1
194
+ MOVQ $(1 << 32 ), BX
195
+ MOVQ BX, (timer_when)(AX)
196
+
197
+ // g->timer.astate &= timerModified
198
+ // g->timer.state &= timerModified
199
+ MOVQ (timer_astate)(AX), CX
200
+ ORQ $const_timerModified<<8|const_timerModified, CX
201
+ MOVQ CX, (timer_astate)(AX)
202
+
203
+ MOVQ (timer_ts)(AX), AX
204
+ CMPQ AX, $0
205
+ JE done
206
+
207
+ // g->timer.ts.minWhenModified = 1
208
+ MOVQ $(1 << 32 ), BX
209
+ MOVQ BX, (timers_minWhenModified)(AX)
210
+
211
+ // len(g->timer.ts.heap)
212
+ MOVQ (timers_heap+8 )(AX), CX
213
+ CMPQ CX, $0
214
+ JE done
215
+
216
+ // offset to last element
217
+ SUBQ $1 , CX
218
+ MOVQ $(timerWhen__size), DX
219
+ IMULQ DX, CX
220
+
221
+ MOVQ (timers_heap)(AX), AX
222
+ CMPQ AX, $0
223
+ JE done
224
+
225
+ // g->timer.ts.heap[len-1]
226
+ ADDQ CX, AX
227
+ JMP check
228
+
229
+ prev:
230
+ SUBQ $(timerWhen__size), AX
231
+ CMPQ AX, $0
232
+ JE done
233
+
234
+ check:
235
+ // find longest timer as *timers.adjust() might be pending
236
+ MOVQ (timerWhen_when)(AX), BX
237
+ MOVQ $((1 << 63 ) - 1 ), CX // math.MaxInt64
238
+ CMPQ CX, BX
239
+ JNE prev
240
+
241
+ // g->timer.ts.heap[off] = 1
242
+ MOVQ $(1 << 32 ), BX
243
+ MOVQ BX, (timerWhen_when)(AX)
244
+
245
+ done:
246
+ RET
247
+
248
+ // Wake modifies a goroutine cached timer for time.Sleep (g.timer) to fire as
249
+ // soon as possible.
250
+ TEXT runtime·Wake(SB),NOFRAME,$0 -8
251
+ MOVQ gp+0 (FP), AX
252
+ JMP runtime·WakeG(SB)
0 commit comments