Struct rayon_core::sleep::Sleep
source · pub(crate) struct Sleep {
worker_sleep_states: Vec<CachePadded<WorkerSleepState>>,
counters: AtomicCounters,
}
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
Implementations§
source§impl Sleep
impl Sleep
pub(crate) fn new(n_threads: usize) -> Sleep
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, has_injected_jobs: impl FnOnce() -> bool, )
fn announce_sleepy(&self) -> JobsEventCounter
fn sleep( &self, idle_state: &mut IdleState, latch: &CoreLatch, has_injected_jobs: impl FnOnce() -> bool, )
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
.