pub(crate) struct Sleep {
worker_sleep_states: Vec<CachePadded<WorkerSleepState>>,
counters: AtomicCounters,
data: Mutex<SleepData>,
}
Expand description
The Sleep
struct is embedded into each registry. It governs the waking and sleeping
of workers. It has callbacks that are invoked periodically at significant events,
such as when workers are looping and looking for work, when latches are set, or when
jobs are published, and it either blocks threads or wakes them in response to these
events. See the [README.md
] in this module for more details.
[README.md
] README.md
Fields§
§worker_sleep_states: Vec<CachePadded<WorkerSleepState>>
One “sleep state” per worker. Used to track if a worker is sleeping and to have them block.
counters: AtomicCounters
§data: Mutex<SleepData>
Implementations§
Source§impl Sleep
impl Sleep
pub(crate) fn new(n_threads: usize) -> Sleep
Sourcepub(crate) fn mark_blocked(
&self,
deadlock_handler: &Option<Box<dyn Fn() + Send + Sync>>,
)
pub(crate) fn mark_blocked( &self, deadlock_handler: &Option<Box<dyn Fn() + Send + Sync>>, )
Mark a Rayon worker thread as blocked. This triggers the deadlock handler if no other worker thread is active
Sourcepub(crate) fn mark_unblocked(&self)
pub(crate) fn mark_unblocked(&self)
Mark a previously blocked Rayon worker thread as unblocked
pub(crate) fn start_looking(&self, worker_index: usize) -> IdleState
pub(crate) fn work_found(&self)
pub(crate) fn no_work_found( &self, idle_state: &mut IdleState, latch: &CoreLatch, thread: &WorkerThread, )
fn announce_sleepy(&self) -> JobsEventCounter
fn sleep( &self, idle_state: &mut IdleState, latch: &CoreLatch, thread: &WorkerThread, )
Sourcepub(crate) fn notify_worker_latch_is_set(&self, target_worker_index: usize)
pub(crate) fn notify_worker_latch_is_set(&self, target_worker_index: usize)
Notify the given thread that it should wake up (if it is sleeping). When this method is invoked, we typically know the thread is asleep, though in rare cases it could have been awoken by (e.g.) new work having been posted.
Sourcepub(crate) fn new_injected_jobs(&self, num_jobs: u32, queue_was_empty: bool)
pub(crate) fn new_injected_jobs(&self, num_jobs: u32, queue_was_empty: bool)
Signals that num_jobs
new jobs were injected into the thread
pool from outside. This function will ensure that there are
threads available to process them, waking threads from sleep
if necessary.
§Parameters
num_jobs
– lower bound on number of jobs available for stealing. We’ll try to get at least one thread per job.
Sourcepub(crate) fn new_internal_jobs(&self, num_jobs: u32, queue_was_empty: bool)
pub(crate) fn new_internal_jobs(&self, num_jobs: u32, queue_was_empty: bool)
Signals that num_jobs
new jobs were pushed onto a thread’s
local deque. This function will try to ensure that there are
threads available to process them, waking threads from sleep
if necessary. However, this is not guaranteed: under certain
race conditions, the function may fail to wake any new
threads; in that case the existing thread should eventually
pop the job.
§Parameters
num_jobs
– lower bound on number of jobs available for stealing. We’ll try to get at least one thread per job.
Sourcefn new_jobs(&self, num_jobs: u32, queue_was_empty: bool)
fn new_jobs(&self, num_jobs: u32, queue_was_empty: bool)
Common helper for new_injected_jobs
and new_internal_jobs
.
fn wake_any_threads(&self, num_to_wake: u32)
fn wake_specific_thread(&self, index: usize) -> bool
Auto Trait Implementations§
impl !Freeze for Sleep
impl RefUnwindSafe for Sleep
impl Send for Sleep
impl Sync for Sleep
impl Unpin for Sleep
impl UnwindSafe for Sleep
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
Source§impl<T> Pointable for T
impl<T> Pointable for T
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 64 bytes