You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
♻️ Decouple context from virtual callback API via unblock_listener
Separate the unblock notification mechanism from the context class into
a dedicated `unblock_listener` interface. This eliminates the need for
virtual function on context itself, allowing each context to be a
simple, concrete object.
The callback pattern is now only used for the unblock event—the only
notification that must happen asynchronously (in ISRs or other threads).
The scheduler can directly inspect context state to determine readiness
and sleep duration without callbacks.
Changes:
- Extract unblock notification into `unblock_listener` interface
- Remove virtual methods from context class
- Update sleep_duration to use microseconds (u32) instead of nanoseconds
to save 4 bytes, reduce the timing requirements on the scheduler, and
to provide a more realistic delay range for most systems.
- Simplify context state inspection for scheduler decision-making
- Add `on_unblock()` listener registration/clearing on context
- Update tests to use new listener-based design
-**Flexible scheduler integration** - Schedulers can poll context state directly, or register an `unblock_listener` for ISR-safe event notification when contexts become unblocked
148
147
-**Proxy contexts** - Support for supervised coroutines with timeout capabilities
149
148
-**Exception propagation** - Proper exception handling through the coroutine chain
150
149
-**Cancellation support** - Clean cancellation with RAII-based resource cleanup
@@ -222,13 +221,35 @@ work.
222
221
223
222
## Core Types
224
223
224
+
### `async::unblock_listener`
225
+
226
+
An interface for receiving notifications when a context becomes unblocked. This
227
+
is the primary mechanism for schedulers to efficiently track which contexts are
228
+
ready for execution without polling. Implement this interface and register it
229
+
with `context::on_unblock()` to be notified when a context transitions to the
230
+
unblocked state.
231
+
232
+
The `on_unblock()` method is called from within `context::unblock()`, which may
233
+
be invoked from ISRs, driver completion handlers, or other threads.
234
+
Implementations must be ISR-safe and noexcept.
235
+
225
236
### `async::context`
226
237
227
-
The base context class that manages coroutine execution and memory. Derived classes must:
238
+
The base context class that manages coroutine execution and memory. Contexts
239
+
are initialized with stack memory via their constructor:
228
240
229
-
1. Provide stack memory via `initialize_stack_memory()`, preferably within the
230
-
constructor.
231
-
2. Implement `do_schedule()` to handle blocking state notifications
241
+
```cpp
242
+
std::array<async::uptr, 1024> my_stack{};
243
+
async::context ctx(my_stack);
244
+
```
245
+
246
+
> [!CRITICAL]
247
+
> The stack memory MUST outlive the context object. The context does not own or
248
+
> copy the stack memory—it only stores a reference to it.
249
+
250
+
Optionally, contexts can register an `unblock_listener` to be notified of state
251
+
changes, or the scheduler can poll the context state directly using `state()`
0 commit comments