Repository navigation
refactor(concurrency): name the while-loop resume markers and add a resume regression test - #23
Merged
zombocoder merged 1 commit intoOct 27, 2026
Conversation
… index The green-threads resume mechanism stores a marker on Coroutine::block_resume_stack when a coroutine suspends inside a while-loop body. WhileStatementNode hardcoded push_back(1) with a "// 1 means resuming body" comment, and read it back via a bare `!= 0` compare: a magic number whose meaning was only discoverable from the comment. Replace both literals with named, file-local constexpr markers (kResumeAtCondition = 0, kResumeInBody = 1) that document the while node as a two-position sequence (condition vs body). Behavior is identical (same values, same comparison); this only removes the magic number. Tests: adds ConcurrencyTest.resume_logic_multi_statement_body, a regression guard that suspends inside a while body with statements both before and after the suspension point, asserting each pre-suspend statement runs once per iteration and each post-suspend statement once per resume. Signed-off-by: svaiml <88979468+svaiml@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A small readability refactor in the green-threads resume path, plus a regression test for it.
WhileStatementNoderecordspush_back(1)onCoroutine::block_resume_stackwhen a coroutinesuspends inside the loop body, and reads it back with a bare
!= 0. The meaning of both numbers livedonly in a comment.
Change
kResumeAtCondition = 0(re-evaluate the condition)and
kResumeInBody = 1(re-enter the body, skipping the condition re-check).Tests
ConcurrencyTest.resume_logic_multi_statement_bodyintests/test_resume_logic.cpp: suspends insidea while body that has statements both before and after the suspension point, and asserts each
pre-suspend statement runs once per iteration and each post-suspend statement once per resume.
Verification
mainwith this branch merged: build OK,o2l_tests527/527 passing.clang-format(repository.clang-format) reports nothing on the changed lines. It still flags the include order of../Runtime/Scheduler.hppin this file, which is the same onmainand left alone here.If you would rather not take a pure refactor, the test alone is still useful as a guard for the resume
logic; happy to split it out.