Struct Shared

Source
struct Shared {
    data: Mutex<Data>,
    thread_condvar: Condvar,
}
Expand description

Shared state and ancillary information

This is always within an Arc.

Fields§

§data: Mutex<Data>

Shared state

§thread_condvar: Condvar

Condition variable for thread scheduling

Signaled when Data.thread_to_run is modified.

Implementations§

Source§

impl Shared

Source

fn subthread_entrypoint<T: Send + 'static>( self: Arc<Self>, id: TaskId, call: impl FnOnce() -> T + Send + 'static, output_tx: Sender<Result<T, Box<dyn Any + Send>>>, )

Main entrypoint function for a Subthread

Entered on a new std::thread thread created by subthread_spawn.

When call completes, sends its returned value T to output_tx.

Source

fn subthread_yield(&self, us: TaskId, set_awake: Option<SetAwake>)

Yield back to the executor from a subthread

Checks that things are in order (in particular, that this task is in the data structure as a subhtread) and switches to the executor thread.

The caller must arrange that the task gets woken.

With SetAwake, sets our task awake, so that we’ll be polled again as soon as we get to the top of the executor’s queue. Otherwise, we’ll be reentered after someone wakes a Waker for the task.

Source

fn thread_context_switch( &self, data: MutexGuard<'_, Data>, us: ThreadDescriptor, them: ThreadDescriptor, )

Switch from (sub)thread us to (sub)thread them

Returns when someone calls thread_context_switch(.., us).

Source

fn thread_context_switch_send_instruction_to_run( &self, data: &mut MutexGuard<'_, Data>, us: ThreadDescriptor, them: ThreadDescriptor, )

Instruct the (sub)thread them to run

Update thread_to_run, which will wake up them’s call to thread_context_switch_waitfor_instruction_to_run.

Must be called from (sub)thread us. Part of thread_context_switch, not normally called directly.

Source

fn thread_context_switch_waitfor_instruction_to_run( &self, data: MutexGuard<'_, Data>, us: ThreadDescriptor, )

Await an instruction for this thread, us, to run

Waits for thread_to_run to be us, waiting for thread_condvar as necessary.

Part of thread_context_switch, not normally called directly.

Source§

impl Shared

Source

fn lock(&self) -> MutexGuard<'_, Data>

Lock and obtain the guard

Convenience method which panics on poison

Trait Implementations§

Source§

impl Default for Shared

Source§

fn default() -> Shared

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

Auto Trait Implementations§

§

impl !Freeze for Shared

§

impl RefUnwindSafe for Shared

§

impl Send for Shared

§

impl Sync for Shared

§

impl Unpin for Shared

§

impl UnwindSafe for Shared

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,