Struct Data

Source
struct Data {
    tasks: DenseSlotMap<Ti, Task>,
    awake: VecDeque<Ti>,
    progressing_until_stalled: Option<ProgressingUntilStalled>,
    scheduling: SchedulingPolicy,
    thread_to_run: ThreadDescriptor,
}
Expand description

Executor’s state

§Task state machine

A task is created in tasks, Awake, so also in awake.

When we poll it, we take it out of awake and set it to Asleep, and then call poll(). Any time after that, it can be made Awake again (and put back onto awake) by the waker (ActualWaker, wrapped in Waker).

The task’s future is of course also present here in this data structure. However, during poll we must release the lock, so we cannot borrow the future from Data. Instead, we move it out. So Task.fut is an Option.

§“Main” task - the argument to block_on

The signature of BlockOn::block_on accepts a non-'static future (and a non-Send/Sync one).

So we cannot store that future in Data because Data is 'static. Instead, this main task future is passed as an argument down the call stack. In the data structure we simply store a placeholder, TaskFutureInfo::Main.

Fields§

§tasks: DenseSlotMap<Ti, Task>

Tasks

Includes tasks spawned with spawn, and also the future passed to block_on.

§awake: VecDeque<Ti>

awake lists precisely: tasks that are Awake, plus maybe stale TaskIds

Tasks are pushed onto the back when woken, so back is the most recently woken.

§progressing_until_stalled: Option<ProgressingUntilStalled>

If a future from progress_until_stalled exists

§scheduling: SchedulingPolicy

Scheduling policy

§thread_to_run: ThreadDescriptor

(Sub)thread we want to run now

At any one time only one thread is meant to be running. Other threads are blocked in condvar wait, waiting for this to change.

Modified only within thread_context_switch_send_instruction_to_run, which takes responsibility for preserving the following invariants:

  1. no-one but the named thread is allowed to modify this field.
  2. after modifying this field, signal thread_condvar

Implementations§

Source§

impl Data

Source

fn insert_task(&mut self, desc: String, fut: TaskFutureInfo) -> TaskId

Insert a task given its TaskFutureInfo and return its TaskId.

Source§

impl Data

Source

fn schedule(&mut self) -> Option<TaskId>

Return the next task to run

The task is removed from awake, but state is not set to Asleep. The caller must restore the invariant!

Source§

impl Data

Source

fn dump_backtraces(&self, f: &mut Formatter<'_>) -> Result

Dump tasks and their sleep location backtraces

Source§

impl Data

Source

fn debug_dump(&mut self)

Convenience function: dump including backtraces, to stderr

Trait Implementations§

Source§

impl Debug for Data

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Data

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Data> for MockExecutor

Source§

fn from(data: Data) -> MockExecutor

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Data

§

impl !RefUnwindSafe for Data

§

impl Send for Data

§

impl !Sync for Data

§

impl Unpin for Data

§

impl !UnwindSafe for Data

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,