Struct rayon_core::registry::Registry

source ·
pub(crate) struct Registry {
    thread_infos: Vec<ThreadInfo>,
    sleep: Sleep,
    injected_jobs: Injector<JobRef>,
    broadcasts: Mutex<Vec<Worker<JobRef>>>,
    panic_handler: Option<Box<dyn Fn(Box<dyn Any + Send>) + Send + Sync>>,
    start_handler: Option<Box<dyn Fn(usize) + Send + Sync>>,
    exit_handler: Option<Box<dyn Fn(usize) + Send + Sync>>,
    terminate_count: AtomicUsize,
}

Fields§

§thread_infos: Vec<ThreadInfo>§sleep: Sleep§injected_jobs: Injector<JobRef>§broadcasts: Mutex<Vec<Worker<JobRef>>>§panic_handler: Option<Box<dyn Fn(Box<dyn Any + Send>) + Send + Sync>>§start_handler: Option<Box<dyn Fn(usize) + Send + Sync>>§exit_handler: Option<Box<dyn Fn(usize) + Send + Sync>>§terminate_count: AtomicUsize

Implementations§

source§

impl Registry

source

pub(crate) fn new<S>( builder: ThreadPoolBuilder<S>, ) -> Result<Arc<Self>, ThreadPoolBuildError>
where S: ThreadSpawn,

source

pub(crate) fn current() -> Arc<Registry>

source

pub(crate) fn current_num_threads() -> usize

Returns the number of threads in the current registry. This is better than Registry::current().num_threads() because it avoids incrementing the Arc.

source

pub(crate) fn current_thread(&self) -> Option<&WorkerThread>

Returns the current WorkerThread if it’s part of this Registry.

source

pub(crate) fn id(&self) -> RegistryId

Returns an opaque identifier for this registry.

source

pub(crate) fn num_threads(&self) -> usize

source

pub(crate) fn catch_unwind(&self, f: impl FnOnce())

source

pub(crate) fn wait_until_primed(&self)

Waits for the worker threads to get up and running. This is meant to be used for benchmarking purposes, primarily, so that you can get more consistent numbers by having everything “ready to go”.

source

pub(crate) fn inject_or_push(&self, job_ref: JobRef)

//////////////////////////////////////////////////////////////////////// MAIN LOOP

So long as all of the worker threads are hanging out in their top-level loop, there is no work to be done. Push a job into the given registry. If we are running on a worker thread for the registry, this will push onto the deque. Else, it will inject from the outside (which is slower).

source

pub(crate) fn inject(&self, injected_job: JobRef)

Push a job into the “external jobs” queue; it will be taken by whatever worker has nothing to do. Use this if you know that you are not on a worker of this registry.

source

fn has_injected_job(&self) -> bool

source

fn pop_injected_job(&self) -> Option<JobRef>

source

pub(crate) fn inject_broadcast( &self, injected_jobs: impl ExactSizeIterator<Item = JobRef>, )

Push a job into each thread’s own “external jobs” queue; it will be executed only on that thread, when it has nothing else to do locally, before it tries to steal other work.

Panics if not given exactly as many jobs as there are threads.

source

pub(crate) fn in_worker<OP, R>(&self, op: OP) -> R
where OP: FnOnce(&WorkerThread, bool) -> R + Send, R: Send,

If already in a worker-thread of this registry, just execute op. Otherwise, inject op in this thread-pool. Either way, block until op completes and return its return value. If op panics, that panic will be propagated as well. The second argument indicates true if injection was performed, false if executed directly.

source

unsafe fn in_worker_cold<OP, R>(&self, op: OP) -> R
where OP: FnOnce(&WorkerThread, bool) -> R + Send, R: Send,

source

unsafe fn in_worker_cross<OP, R>( &self, current_thread: &WorkerThread, op: OP, ) -> R
where OP: FnOnce(&WorkerThread, bool) -> R + Send, R: Send,

source

pub(crate) fn increment_terminate_count(&self)

Increments the terminate counter. This increment should be balanced by a call to terminate, which will decrement. This is used when spawning asynchronous work, which needs to prevent the registry from terminating so long as it is active.

Note that blocking functions such as join and scope do not need to concern themselves with this fn; their context is responsible for ensuring the current thread-pool will not terminate until they return.

The global thread-pool always has an outstanding reference (the initial one). Custom thread-pools have one outstanding reference that is dropped when the ThreadPool is dropped: since installing the thread-pool blocks until any joins/scopes complete, this ensures that joins/scopes are covered.

The exception is ::spawn(), which can create a job outside of any blocking scope. In that case, the job itself holds a terminate count and is responsible for invoking terminate() when finished.

source

pub(crate) fn terminate(&self)

Signals that the thread-pool which owns this registry has been dropped. The worker threads will gradually terminate, once any extant work is completed.

source

pub(crate) fn notify_worker_latch_is_set(&self, target_worker_index: usize)

Notify the worker that the latch they are sleeping on has been “set”.

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.