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
This PR refactors the
async_contextlibrary by merging theschedulerclass into thecontextbase class, improving memory efficiency, simplifying ownership semantics, and reducing indirection. It also introduces a newproxy_contextcreation method (from) and removes redundant context parameters in scheduling calls.Changes Overview
Merged
schedulerintocontext:contextclass is now an abstract base class with pure virtual function (do_schedule) that are implemented by derivedcontextclasses.schedulerobject and reduces context size down to just 64 bytes on 64-bit systems.Stack Memory Ownership:
contextclass has a newinitialize_stack_memorymethod to set up the stack.Proxy Context Implementation:
proxy_contextclass now implements the proxy pattern by delegating scheduling to the original context.from(context& p_parent)is added for constructing proxies.Simplified Scheduling API:
context& p_contextparameter fromschedule()calls.schedule(blocked_by state, block_info info).Memory Efficiency Gains:
Updated Dependencies & Build Files:
strong_ptrdependencycontext-based design.Benefits
async::contextnow fits within a single cache lineExample Usage
Testing & Compatibility
benchmark_contextfor performance measurement.proxy_context::from(parent)instead of the previous proxy constructor.Conclusion
This PR significantly refactors
async_contextto better align with embedded systems’ constraints by reducing memory overhead, simplifying ownership models, and enhancing flexibility for different scheduler implementations.This PR message was generated by
Qwen3-coder:30busing LM studio and based on a diff of this change. The content was read and edited by myself.