Async core#22561
Draft
EdmondDantes wants to merge 2 commits into
Draft
Conversation
615d050 to
ed9fe03
Compare
d7284f3 to
7aec489
Compare
A mechanism-only async core, rethought from the TrueAsync ABI (2973-line header) down to ~350 lines. The core contains NO policy: no scheduler, no reactor, no event system. All behaviour arrives through function-pointer slots registered by a provider. The API consists of: - zend_coroutine_t: thin coroutine structure. The lifecycle status (created/queued/running/suspended/finished) is packed into the low 4 bits of the 32-bit flags word; modifier flags (cancelled, main) start at bit 4. No embedded waker - how a coroutine waits is the scheduler's implementation detail. Instead, whoever suspends a coroutine may attach an awaiting_info handler that describes the wait for diagnostics. - Execution-flow context: fully opaque type accessed through slots - get_context(coroutine) with NULL meaning the current coroutine (ZEND_ASYNC_CURRENT_CONTEXT), context_find/set/unset. Storage, inheritance and lifetime live in the provider. - Scheduler slots registered via a versioned struct (zend_async_scheduler_api_t): new_coroutine, enqueue_coroutine, suspend, resume, cancel, launch, shutdown, get_class_ce, call_on_main_stack + the four context slots. The size field keeps registration forward-compatible: new slots are appended at the end only. - Per-thread globals: state, current/main coroutine, live coroutine count. - Exception class registry: zend_async_class enum resolved through the get_class_ce slot; consumers throw with the regular engine API. Unregistered slots fail with a clear error, so the API is inert until a scheduler module registers itself.
Each fiber can be associated with a coroutine (fiber->coroutine, NULL = legacy mode with unchanged behaviour). The caller field becomes a union: in coroutine mode the fiber remembers the coroutine that resumed it instead of a fiber context - the single point-to-point link that replaces TrueAsync's resume/yield event pair. Phase 2 (the actual cooperative switching through the scheduler slots) requires a working scheduler to test against and comes with the reference extension.
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.
A lightweight asynchronous core without complex logic.