ZeroPool

Struct ZeroPool 

Source
pub struct ZeroPool { /* private fields */ }

Implementations§

Source§

impl ZeroPool

Source

pub fn new() -> Self

Creates a new thread pool with worker count equal to available parallelism

Worker count is determined by std::thread::available_parallelism(), falling back to 1 if unavailable. This is usually the optimal choice for CPU-bound workloads.

§Examples
use zero_pool::ZeroPool;
let pool = ZeroPool::new();
Source

pub fn with_workers(worker_count: usize) -> Self

Creates a new thread pool with the specified number of workers

Use this when you need precise control over the worker count, for example when coordinating with other thread pools or when you know the optimal count for your specific workload.

§Panics

Panics if worker_count is 0.

use zero_pool::ZeroPool;
let pool = ZeroPool::with_workers(4);
Source

pub fn submit_raw_task( &self, task_fn: TaskFnPointer, params: TaskParamPointer, ) -> TaskFuture

Submit a single task using raw function and parameter pointers

This is the lowest-level submission method with minimal overhead. Most users should prefer the type-safe submit_task method.

§Safety

The parameter pointer must remain valid until the returned future completes. The caller must ensure the pointer points to the correct parameter type expected by the task function.

§Examples
use zero_pool::{ZeroPool, TaskFnPointer, TaskParamPointer, zp_task_params, zp_define_task_fn, zp_write};

zp_task_params! {
    MyTask { value: u64, result: *mut u64 }
}

zp_define_task_fn!(my_task, MyTask, |params| {
    zp_write!(params.result, params.value * 2);
});

let pool = ZeroPool::new();
let mut result = 0u64;
let params = MyTask::new(42, &mut result);
let future = pool.submit_raw_task(
    my_task as TaskFnPointer,
    &params as *const _ as TaskParamPointer
);
future.wait();
Source

pub fn submit_raw_task_batch(&self, tasks: &[TaskItem]) -> TaskFuture

Submit a batch of tasks using raw work items

This method provides optimal performance for pre-converted task batches. Use uniform_tasks_to_pointers to convert typed tasks efficiently, or build work items manually for mixed task types.

§Examples
use zero_pool::{ZeroPool, uniform_tasks_to_pointers, zp_task_params, zp_define_task_fn, zp_write};

zp_task_params! {
    MyTask { value: u64, result: *mut u64 }
}

zp_define_task_fn!(my_task, MyTask, |params| {
    zp_write!(params.result, params.value * 2);
});

let pool = ZeroPool::new();
let mut results = [0u64; 2];
let params_vec = [
    MyTask::new(1, &mut results[0]),
    MyTask::new(2, &mut results[1])
];
let tasks = uniform_tasks_to_pointers(my_task, &params_vec);
let future = pool.submit_raw_task_batch(&tasks);
future.wait();
Source

pub fn submit_task<T>(&self, task_fn: TaskFnPointer, params: &T) -> TaskFuture

Submit a single typed task with automatic pointer conversion

This method provides type safety while maintaining performance. The parameter struct must remain valid until the future completes. This is the recommended method for submitting individual tasks.

§Examples
use zero_pool::{ZeroPool, zp_task_params, zp_define_task_fn, zp_write};

zp_task_params! {
    MyTask { value: u64, result: *mut u64 }
}

zp_define_task_fn!(my_task_fn, MyTask, |params| {
    zp_write!(params.result, params.value * 2);
});

let pool = ZeroPool::new();
let mut result = 0u64;
let task_params = MyTask::new(42, &mut result);
let future = pool.submit_task(my_task_fn, &task_params);
future.wait();
assert_eq!(result, 84);
Source

pub fn submit_batch_uniform<T>( &self, task_fn: TaskFnPointer, params_vec: &[T], ) -> TaskFuture

Submit a batch of uniform tasks with automatic pointer conversion

All tasks in the batch must be the same type and use the same task function. This method handles the pointer conversion automatically and is the most convenient way to submit large batches of similar work.

§Examples
use zero_pool::{ZeroPool, zp_task_params, zp_define_task_fn, zp_write};

zp_task_params! {
    MyTask { value: u64, result: *mut u64 }
}

zp_define_task_fn!(my_task_fn, MyTask, |params| {
    zp_write!(params.result, params.value * 2);
});

let pool = ZeroPool::new();
let mut results = vec![0u64; 1000];
let tasks: Vec<_> = (0..1000)
    .map(|i| MyTask::new(i as u64, &mut results[i]))
    .collect();
let future = pool.submit_batch_uniform(my_task_fn, &tasks);
future.wait();

Trait Implementations§

Source§

impl Drop for ZeroPool

Source§

fn drop(&mut self)

Executes the destructor for this 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.