Expand description
Stackful, executor-affine native coroutines. See README.md for the safety contract.
Structs§
- Cancelled
- The driver was dropped before completion: the coroutine was cancelled, and its suspended frames were discarded without running anything on them.
- Coroutine
- A native coroutine. Neither Send nor Sync: poll it on its creating executor thread.
- Join
Handle - One completion observer, sharing the coroutine’s control allocation.
- Stack
- Single heap allocation, aligned to 16 bytes, with a 64-byte painted lower guard. This detects damage at boundaries; it does not provide memory protection.
- Stack
Allocator - Allocator hooks used to obtain and release coroutine
Stackbacking memory.
Enums§
- TlsError
- Failure accessing coroutine-local storage.
Constants§
- DEFAULT_
MIN_ STACK_ SIZE - Default minimum usable stack size in bytes applied by
Stack::new. - MAX_
CORES - Maximum number of bare-metal CPU cores tracked by the per-core current-coroutine table.
- MIN_
STACK_ SIZE - Smallest usable stack size in bytes permitted by
Stack::with_min_size. - TLS_
SLOTS - Number of coroutine-local storage slots stored inline in each coroutine control block.
Functions§
- control_
allocation_ size - Bytes in the shared control allocation, including the two Rc reference counts.
- drive
- Drive a coroutine as a normal local Embassy future.
- exit⚠
- End the running coroutine at once with
status, as if its entry had returned it. - is_
in_ coroutine - Whether execution is currently on a native coroutine stack.
- native_
context - Pointer privately installed by the native ABI; null on other coroutines.
- set_
core_ ⚠id_ provider - Register the platform hook that identifies the calling CPU core on bare metal.
- set_
native_ ⚠context - Install the native ABI’s private context on the running coroutine.
- set_
stack_ ⚠allocator - Register the allocator used for subsequent coroutine
Stackallocations. - spawn⚠
- Spawn on the calling task’s executor, preserving stack/thread affinity. The manager additionally allocates its existing task pool, metadata and join signal.
- spawn_
with_ ⚠driver - Like
spawn_with_result, with a local future that drives the entry coroutine. - spawn_
with_ ⚠result - Like
spawn, converting the exit status before signaling the task join handle. - suspend_
on - Await from native code. Outside a coroutine this preserves task::block_on behavior. No heap allocation occurs here. The future and output stay on the native stack. Do not call this from a future’s poll method: poll methods must return Pending. Do not call it while holding a critical section: the interrupt mask is not switched with the stack, so the executor would run with interrupts masked.
- suspend_
on_ cancellable - Like
suspend_on, but drops this future in place if the driver cancels the coroutine. The future’s destructor runs on the executor’s stack. - tls_get
- Read a coroutine-local storage slot for the currently running coroutine.
Slots start at
0. No heap allocation occurs. ReturnsTlsError::InvalidSlotifslot >= TLS_SLOTS, orTlsError::NotInCoroutineoutside a running coroutine. - tls_set
- Write a coroutine-local storage slot for the currently running coroutine.
No heap allocation occurs.
Returns
TlsError::InvalidSlotifslot >= TLS_SLOTS, orTlsError::NotInCoroutineoutside a running coroutine.
Type Aliases§
- Core
IdProvider - Platform hook returning the calling CPU core’s index in
0..MAX_CORES. - Stack
Allocate Fn - Function that allocates backing memory for a coroutine
Stackwith the requestedLayout. - Stack
Deallocate Fn - Function that releases backing memory previously returned by its paired
StackAllocateFnwith the exact sameLayout.