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

source

pub(super) fn new() -> AtomicCounters

source

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.

source

fn try_exchange( &self, old_value: Counters, new_value: Counters, ordering: Ordering, ) -> bool

source

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.

source

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.

source

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.

source

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).

source

pub(super) fn try_add_sleeping_thread(&self, old_value: Counters) -> bool

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.