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: CondvarCondition variable for thread scheduling
Signaled when Data.thread_to_run
is modified.
Implementations§
Sourcefn 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>>>,
)
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.
Sourcefn subthread_yield(&self, us: TaskId, set_awake: Option<SetAwake>)
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.
Sourcefn thread_context_switch(
&self,
data: MutexGuard<'_, Data>,
us: ThreadDescriptor,
them: ThreadDescriptor,
)
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).
Sourcefn thread_context_switch_send_instruction_to_run(
&self,
data: &mut MutexGuard<'_, Data>,
us: ThreadDescriptor,
them: ThreadDescriptor,
)
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.
Sourcefn thread_context_switch_waitfor_instruction_to_run(
&self,
data: MutexGuard<'_, Data>,
us: ThreadDescriptor,
)
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.
Sourcefn lock(&self) -> MutexGuard<'_, Data>
fn lock(&self) -> MutexGuard<'_, Data>
Lock and obtain the guard
Convenience method which panics on poison
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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