Skip to content

Commit

Permalink
early returns from if there are no active threads
Browse files Browse the repository at this point in the history
  • Loading branch information
pufferfish101007 committed Sep 1, 2023
1 parent e865f58 commit 827f55a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/targets/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,10 @@ impl From<IrProject> for WebWasmFile {
align: 2,
memory_index: 0,
}));
tick_func.instruction(&Instruction::LocalTee(1));
tick_func.instruction(&Instruction::I32Eqz);
tick_func.instruction(&Instruction::BrIf(0));
tick_func.instruction(&Instruction::LocalGet(1));
tick_func.instruction(&Instruction::I32Const(THREAD_BYTE_LEN));
tick_func.instruction(&Instruction::I32Mul);
tick_func.instruction(&Instruction::I32Const(THREAD_BYTE_LEN));
Expand Down Expand Up @@ -1347,7 +1351,7 @@ impl From<IrProject> for WebWasmFile {
$innertickloop: while (Date.now() - thisTickStartTime < 23 && new Uint8Array(memory.buffer)[{rr_offset}] === 0) {{
/*console.log('inner')*/
tick();
if (!new Uint32Array(memory.buffer).slice({threads_offset}/4, {threads_offset}/4 + new Uint32Array(memory.buffer)[{thn_offset}/4] + 1).some(x => x > 0)) {{
if (new Uint32Array(memory.buffer)[{thn_offset}/4] === 0) {{
break $outertickloop;
}}
}}
Expand All @@ -1363,7 +1367,7 @@ impl From<IrProject> for WebWasmFile {
/*exit(1);*/
}});
}})
", target_names=&project.targets, buf=&wasm_bytes, rr_offset=byte_offset::REDRAW_REQUESTED, threads_offset=byte_offset::THREADS, thn_offset=byte_offset::THREAD_NUM), wasm_bytes }
", target_names=&project.targets, buf=&wasm_bytes, rr_offset=byte_offset::REDRAW_REQUESTED, thn_offset=byte_offset::THREAD_NUM), wasm_bytes }
}
}

Expand Down

0 comments on commit 827f55a

Please sign in to comment.