Skip to content

Commit

Permalink
Fix an issue where a timeout could be triggered immediately
Browse files Browse the repository at this point in the history
If a message arrived between `lopp_rec` and `wait_timeout`, the execution
didn't resume to testing the received message but instead proceeded to the
`timeout` opcode. As a result, a timeout occurred immediately.

Signed-off-by: Paul Guyot <[email protected]>
  • Loading branch information
pguyot committed Dec 24, 2024
1 parent 546ac2b commit f305419
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ might lead to a crash in certain situations.
- Fix corruption when dealing with specific situations that involve more than 16 x registers when
certain VM instructions are used.
- Fixed ESP32 GPIO interrupt trigger `none`
- Fixed an issue where a timeout would occur immediately in a race condition

## [0.6.5] - 2024-10-15

Expand Down
14 changes: 5 additions & 9 deletions src/libAtomVM/opcodesswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -2551,14 +2551,13 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
}

if (needs_to_wait) {
ctx->saved_ip = saved_pc;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
ctx->restore_trap_handler = &&wait_timeout_trap_handler;
#pragma GCC diagnostic pop
ctx->saved_module = mod;
ctx = scheduler_wait(ctx);
goto schedule_in;
SCHEDULE_WAIT(mod, saved_pc);
} else {
JUMP_TO_ADDRESS(mod->labels[label]);
}
#endif

Expand Down Expand Up @@ -3193,10 +3192,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
if (LIKELY(remaining_reductions)) {
JUMP_TO_ADDRESS(mod->labels[label]);
} else {
ctx->saved_ip = mod->labels[label];
ctx->saved_module = mod;
ctx = scheduler_next(ctx->global, ctx);
goto schedule_in;
SCHEDULE_NEXT(mod, mod->labels[label]);
}
#endif
break;
Expand Down Expand Up @@ -6394,7 +6390,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
case OP_RECV_MARKER_CLEAR: {
DEST_REGISTER(reg_a);
DECODE_DEST_REGISTER(reg_a, pc);
TRACE("recv_marker_clean/1: reg1=%c%i\n", T_DEST_REG(reg_a));
TRACE("recv_marker_clear/1: reg1=%c%i\n", T_DEST_REG(reg_a));
break;
}

Expand Down

0 comments on commit f305419

Please sign in to comment.