pub struct LocalExecutor { /* private fields */ }Expand description
A single-thread executor whose owner may migrate between CPUs.
The executor is deliberately !Send and !Sync: only its scheduler thread
may spawn, poll, park, or shut down futures. Its heap-pinned shared header is
retained by coroutine allocations, so late wakers never address the local
owner object after it has been dropped.
Implementations§
Source§impl LocalExecutor
impl LocalExecutor
Sourcepub fn new(owner_wake: ThreadWakeHandle) -> Result<Self, TaskError>
pub fn new(owner_wake: ThreadWakeHandle) -> Result<Self, TaskError>
Creates an executor for the calling scheduler thread.
The owner identity is derived from the direct wake header rather than a caller-supplied integer, and is checked against the currently running scheduler thread.
§Errors
Returns a scheduler facade error before runtime initialization, or
TaskError::ExecutorOwnerMismatch when owner_wake belongs to another
thread.
Sourcepub fn owner_thread(&self) -> ThreadId
pub fn owner_thread(&self) -> ThreadId
Returns the scheduler thread that owns this executor.
Sourcepub fn spawn<F>(&self, future: F) -> CoroutineId
pub fn spawn<F>(&self, future: F) -> CoroutineId
Allocates and schedules a 'static coroutine for the owner thread.
future need not implement Send; it is polled and dropped only by the
executor owner. Allocation happens here in ordinary thread context, never
in a waker operation.
Sourcepub fn run<F, P>(&self, future: F, park: P) -> F::Output
pub fn run<F, P>(&self, future: F, park: P) -> F::Output
Runs one possibly borrowing future to completion on the owner thread.
park is called only after the executor-side lost-wake handshake has
completed. It must pass the supplied ExecutorParkCondition into the
OS scheduler’s predicate-aware park operation. Checking the condition
before an unconditional park is insufficient because scheduler wake
consumption may race between those two operations. The future is dropped
on the owner before this method returns or unwinds.
Sourcepub fn run_ready_batch(&self) -> PollBatch
pub fn run_ready_batch(&self) -> PollBatch
Polls at most 64 ready coroutines from one queue snapshot.
Wakes produced while a future is being polled are published to the next snapshot, so a self-waking future cannot consume the current batch.
Sourcepub fn has_ready(&self) -> bool
pub fn has_ready(&self) -> bool
Reports whether this executor has a coroutine ready for a future batch.
Sourcepub fn prepare_park(&self) -> Option<ParkToken<'_>>
pub fn prepare_park(&self) -> Option<ParkToken<'_>>
Begins the NOTIFIED/PARKING/PARKED lost-wake handshake.
The caller must hold the returned token across the task-system park
operation. A wake after this function succeeds observes PARKED, publishes
NOTIFIED, and wakes the owner through its direct thread wake header.