DispatchPoolBuilder

Struct DispatchPoolBuilder 

Source
pub struct DispatchPoolBuilder { /* private fields */ }
Expand description

A builder for DispatchPool supporting an extenstive set of configuration options.

Implementations§

Source§

impl DispatchPoolBuilder

Source

pub fn new() -> DispatchPoolBuilder

Create new dispatch pool builder, for configuration.

Source

pub fn pool_size(&mut self, size: usize) -> &mut Self

Set the fixed number of threads in the pool.

This must at least be one (1) thread, asserted. However the value is ignored (and no threads are spawned) if queue_length is zero (0).

Default: the number of logical CPU’s minus one, but one at minimum:

Detected CPUsDefault Pool Size
01
11
21
32
43

Detected CPUs may be influenced by simultaneous multithreading (SMT, e.g. Intel hyper-threading) or scheduler affinity. Zero (0) detected CPUs is likely an error.

Source

pub fn queue_length(&mut self, length: usize) -> &mut Self

Set the length (aka maximum capacity or depth) of the associated dispatch task queue.

The length may be zero, in which case the pool is always considered full and no threads are spawned. If the queue is ever full, the oldest tasks will be executed on the calling thread, see DispatchPool::spawn.

Default: unbounded (unlimited)

Source

pub fn ignore_panics(&mut self, ignore: bool) -> &mut Self

Set whether to catch and ignore unwinds for dispatch tasks that panic, or to abort.

If true, panics are ignored. Note that the unwind safety of dispatched tasks is not well assured by the UnwindSafe marker trait and may later result in undefined behavior (UB) or logic bugs.

If false, a panic in a dispatch pool thread will result in process abort.

Default: false

Source

pub fn stack_size(&mut self, stack_size: usize) -> &mut Self

Set the stack size in bytes for each thread in the pool.

Default: the default thread stack size.

Source

pub fn name_prefix<S: Into<String>>(&mut self, name_prefix: S) -> &mut Self

Set name prefix for threads in the pool.

The (unique) thread index is appended to form the complete thread name.

Default: “dpx-pool-N-” where N is a 0-based global pool counter.

Source

pub fn after_start<F>(&mut self, f: F) -> &mut Self
where F: Fn(usize) + Send + Sync + 'static,

Set a closure to be called immediately after each thread is started.

The closure is passed a 0-based index of the thread.

Default: None

Source

pub fn before_stop<F>(&mut self, f: F) -> &mut Self
where F: Fn(usize) + Send + Sync + 'static,

Set a closure to be called immediately before a pool thread exits.

The closure is passed a 0-based index of the thread.

Default: None

Source

pub fn create(&mut self) -> DispatchPool

Create a new DispatchPool with the provided configuration.

Trait Implementations§

Source§

impl Default for DispatchPoolBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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