Struct rayon_core::sleep::counters::AtomicCounters
source · pub(super) struct AtomicCounters {
value: AtomicUsize,
}
Fields§
§value: AtomicUsize
Packs together a number of counters. The counters are ordered as
follows, from least to most significant bits (here, we assuming
that THREADS_BITS
is equal to 10):
- Bits 0..10: Stores the number of sleeping threads
- Bits 10..20: Stores the number of inactive threads
- Bits 20..: Stores the job event counter (JEC)
This uses 10 bits (THREADS_BITS
) to encode the number of threads. Note
that the total number of bits (and hence the number of bits used for the
JEC) will depend on whether we are using a 32- or 64-bit architecture.
Implementations§
source§impl AtomicCounters
impl AtomicCounters
pub(super) fn new() -> AtomicCounters
sourcepub(super) fn load(&self, ordering: Ordering) -> Counters
pub(super) fn load(&self, ordering: Ordering) -> Counters
Load and return the current value of the various counters. This value can then be given to other method which will attempt to update the counters via compare-and-swap.
fn try_exchange( &self, old_value: Counters, new_value: Counters, ordering: Ordering, ) -> bool
sourcepub(super) fn add_inactive_thread(&self)
pub(super) fn add_inactive_thread(&self)
Adds an inactive thread. This cannot fail.
This should be invoked when a thread enters its idle loop looking for work. It is decremented when work is found. Note that it is not decremented if the thread transitions from idle to sleepy or sleeping; so the number of inactive threads is always greater-than-or-equal to the number of sleeping threads.
sourcepub(super) fn increment_jobs_event_counter_if(
&self,
increment_when: impl Fn(JobsEventCounter) -> bool,
) -> Counters
pub(super) fn increment_jobs_event_counter_if( &self, increment_when: impl Fn(JobsEventCounter) -> bool, ) -> Counters
Increments the jobs event counter if increment_when
, when applied to
the current value, is true. Used to toggle the JEC from even (sleepy) to
odd (active) or vice versa. Returns the final value of the counters, for
which increment_when
is guaranteed to return false.
sourcepub(super) fn sub_inactive_thread(&self) -> usize
pub(super) fn sub_inactive_thread(&self) -> usize
Subtracts an inactive thread. This cannot fail. It is invoked when a thread finds work and hence becomes active. It returns the number of sleeping threads to wake up (if any).
See add_inactive_thread
.
sourcepub(super) fn sub_sleeping_thread(&self)
pub(super) fn sub_sleeping_thread(&self)
Subtracts a sleeping thread. This cannot fail, but it is only safe to do if you you know the number of sleeping threads is non-zero (i.e., because you have just awoken a sleeping thread).