MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / tick

Function tick

packages/node/src/worker/engineWorker.ts:291–539  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

289}
290
291function tick(): void {
292 if (!runtimeState.running) return;
293 if (runtimeState.engineId === null) return;
294
295 let didSubmitDrawlistThisTick = false;
296 let didFrameWork = false;
297 let didEventWork = false;
298 let submittedFrameSeq: number | null = null;
299
300 if (runtimeState.pendingFrame !== null) {
301 const frame = runtimeState.pendingFrame;
302 runtimeState.pendingFrame = null;
303 emitFrameAuditNow("frame.submit.begin", frame.frameSeq, {
304 transport: frame.transport,
305 byteLen: frame.byteLen,
306 ...(frame.transport === FRAME_TRANSPORT_SAB_V1
307 ? { slotIndex: frame.slotIndex, slotToken: frame.slotToken }
308 : {}),
309 });
310 let res = -1;
311 let sabInUse = false;
312 let staleSabFrame = false;
313 try {
314 if (frame.transport === FRAME_TRANSPORT_TRANSFER_V1) {
315 const view = new Uint8Array(frame.buf, 0, frame.byteLen);
316 if (frameAudit.enabled) {
317 const fp = drawlistFingerprint(view);
318 setFrameAuditMetaNow(frame.frameSeq, {
319 transport: frame.transport,
320 byteLen: frame.byteLen,
321 hash32: fp.hash32,
322 prefixHash32: fp.prefixHash32,
323 cmdCount: fp.cmdCount,
324 totalSize: fp.totalSize,
325 });
326 emitFrameAuditNow("frame.submit.payload", frame.frameSeq, fp);
327 }
328 res = native.engineSubmitDrawlist(runtimeState.engineId, view);
329 } else {
330 if (runtimeState.frameTransport.kind !== FRAME_TRANSPORT_SAB_V1) {
331 throw new Error("SAB frame transport unavailable");
332 }
333 if (frame.slotIndex < 0 || frame.slotIndex >= runtimeState.frameTransport.slotCount) {
334 throw new Error(`invalid SAB frame slot index: ${String(frame.slotIndex)}`);
335 }
336 const token = Atomics.load(runtimeState.frameTransport.tokens, frame.slotIndex);
337 if (token !== frame.slotToken) {
338 staleSabFrame = true;
339 } else {
340 const prev = Atomics.compareExchange(
341 runtimeState.frameTransport.states,
342 frame.slotIndex,
343 FRAME_SAB_SLOT_STATE_READY,
344 FRAME_SAB_SLOT_STATE_IN_USE,
345 );
346 if (prev !== FRAME_SAB_SLOT_STATE_READY) {
347 const tokenAfter = Atomics.load(runtimeState.frameTransport.tokens, frame.slotIndex);
348 if (tokenAfter !== frame.slotToken) {

Callers 2

scheduleTickNowFunction · 0.50
scheduleTickFunction · 0.50

Calls 15

emitFrameAuditNowFunction · 0.85
setFrameAuditMetaNowFunction · 0.85
releasePendingFrameNowFunction · 0.85
postFrameStatusNowFunction · 0.85
drainNativeFrameAuditNowFunction · 0.85
fatalFunction · 0.85
deleteFrameAuditNowFunction · 0.85
postFrameAcceptedNowFunction · 0.85
armSabFrameWakeLocalFunction · 0.85
postToMainFunction · 0.85
scheduleTickNowLocalFunction · 0.85

Tested by

no test coverage detected