Struct mmtk::scheduler::worker_monitor::WorkerMonitor
source · pub(crate) struct WorkerMonitor {
sync: Mutex<WorkerMonitorSync>,
workers_have_anything_to_do: Condvar,
}
Expand description
A data structure for synchronizing workers with each other and with mutators.
Unlike GCWorkerShared
, there is only one instance of WorkerMonitor
.
- It allows workers to park and unpark.
- It allows mutators to notify workers to schedule a GC.
Fields§
§sync: Mutex<WorkerMonitorSync>
The synchronized part.
workers_have_anything_to_do: Condvar
Workers wait on this when idle. Notified if workers have things to do. That include:
- any work packets available, and
- any field in
sync.goals.requests
set to true.
Implementations§
source§impl WorkerMonitor
impl WorkerMonitor
pub fn new(worker_count: usize) -> Self
sourcepub fn make_request(&self, goal: WorkerGoal)
pub fn make_request(&self, goal: WorkerGoal)
Make a request. Can be called by a mutator to request the workers to work towards the
given goal
.
sourcepub fn notify_work_available(&self, all: bool)
pub fn notify_work_available(&self, all: bool)
Wake up workers when more work packets are made available for workers, or a mutator has requested the GC workers to schedule a GC.
sourcepub fn park_and_wait<F>(
&self,
ordinal: usize,
on_last_parked: F
) -> Result<(), WorkerShouldExit>
pub fn park_and_wait<F>( &self, ordinal: usize, on_last_parked: F ) -> Result<(), WorkerShouldExit>
Park a worker and wait on the CondVar workers_have_anything_to_do
.
If it is the last worker parked, on_last_parked
will be called.
The argument of on_last_parked
is true if sync.gc_requested
is true
.
The return value of on_last_parked
will determine whether this worker and other workers
will wake up or block waiting.
This function returns Ok(())
if the current worker should continue working,
or Err(WorkerShouldExit)
if the current worker should exit now.
sourcepub fn on_all_workers_exited(&self)
pub fn on_all_workers_exited(&self)
Called when all workers have exited.
Auto Trait Implementations§
impl RefUnwindSafe for WorkerMonitor
impl Send for WorkerMonitor
impl Sync for WorkerMonitor
impl Unpin for WorkerMonitor
impl UnwindSafe for WorkerMonitor
Blanket Implementations§
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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