Skip to main content

LocalExecutor

Struct LocalExecutor 

Source
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

Source

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.

Source

pub fn owner_thread(&self) -> ThreadId

Returns the scheduler thread that owns this executor.

Source

pub fn spawn<F>(&self, future: F) -> CoroutineId
where F: Future<Output = ()> + 'static,

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.

Source

pub fn run<F, P>(&self, future: F, park: P) -> F::Output
where F: Future, P: FnMut(&ExecutorParkCondition<'_>),

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.

Source

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.

Source

pub fn has_ready(&self) -> bool

Reports whether this executor has a coroutine ready for a future batch.

Source

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.

Trait Implementations§

Source§

impl Drop for LocalExecutor

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.