Skip to main content

Crate stackful

Crate stackful 

Source
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.
JoinHandle
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.
StackAllocator
Allocator hooks used to obtain and release coroutine Stack backing 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 Stack allocations.
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. Returns TlsError::InvalidSlot if slot >= TLS_SLOTS, or TlsError::NotInCoroutine outside a running coroutine.
tls_set
Write a coroutine-local storage slot for the currently running coroutine. No heap allocation occurs. Returns TlsError::InvalidSlot if slot >= TLS_SLOTS, or TlsError::NotInCoroutine outside a running coroutine.

Type Aliases§

CoreIdProvider
Platform hook returning the calling CPU core’s index in 0..MAX_CORES.
StackAllocateFn
Function that allocates backing memory for a coroutine Stack with the requested Layout.
StackDeallocateFn
Function that releases backing memory previously returned by its paired StackAllocateFn with the exact same Layout.