pub struct TPool { /* private fields */ }Expand description
Thread pool handle — equivalent to TPool* in the C API.
TPool_create → TPool::new
TPool_free → Drop for TPool (joins workers automatically)
TPool_submitJob → TPool::submit_job
TPool_jobsCompleted → TPool::jobs_completed
Implementations§
Source§impl TPool
impl TPool
Sourcepub fn new(nb_threads: usize, queue_size: usize) -> Option<Self>
pub fn new(nb_threads: usize, queue_size: usize) -> Option<Self>
TPool_create(nbThreads, queueSize) — returns None on failure.
nbThreads must be ≥ 1, queueSize must be ≥ 1.
The C code allocates one extra queue slot to distinguish full vs. empty;
here crossbeam_channel::bounded(queue_size + nb_threads) plays the
same role as the semaphore initialised to queueSize + nbWorkers in the
Windows implementation.
Sourcepub fn submit_job(&self, job: Box<dyn FnOnce() + Send + 'static>)
pub fn submit_job(&self, job: Box<dyn FnOnce() + Send + 'static>)
TPool_submitJob(ctx, job_function, arg) — may block if queue is full.
In C the caller passes a raw void (*fn)(void*) + void* arg.
In Rust the equivalent is a Box<dyn FnOnce() + Send> closure that
has already captured its argument, eliminating the void* anti-pattern.
Sourcepub fn jobs_completed(&self)
pub fn jobs_completed(&self)
TPool_jobsCompleted(ctx) — blocks until all submitted jobs have finished.
Does NOT shut down the pool; it can accept further jobs afterwards, identical to the C semantics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TPool
impl !RefUnwindSafe for TPool
impl Send for TPool
impl Sync for TPool
impl Unpin for TPool
impl UnsafeUnpin for TPool
impl !UnwindSafe for TPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more