use crate::par_thread_pool::ParThreadPool;
use core::num::NonZeroUsize;
use pond::{Pool, Scope};
pub struct PondPool(Pool, NonZeroUsize);
impl PondPool {
pub fn new_threads_unbounded(num_threads: usize) -> Self {
let num_threads = num_threads.min(1);
let pool = Pool::new_threads_unbounded(num_threads);
#[allow(clippy::missing_panics_doc)]
Self(pool, NonZeroUsize::new(num_threads).expect(">0"))
}
pub fn inner(&self) -> &Pool {
&self.0
}
pub fn inner_mut(&mut self) -> &mut Pool {
&mut self.0
}
pub fn into_inner(self) -> Pool {
self.0
}
}
impl ParThreadPool for PondPool {
type ScopeRef<'s, 'env, 'scope>
= Scope<'env, 'scope>
where
'scope: 's,
'env: 'scope + 's;
fn run_in_scope<'s, 'env, 'scope, W>(s: &Self::ScopeRef<'s, 'env, 'scope>, work: W)
where
'scope: 's,
'env: 'scope + 's,
W: Fn() + Send + 'scope + 'env,
{
s.execute(work);
}
fn scoped_computation<'env, 'scope, F>(&'env mut self, f: F)
where
'env: 'scope,
for<'s> F: FnOnce(Scope<'env, 'scope>) + Send,
{
self.0.scoped(f)
}
fn max_num_threads(&self) -> NonZeroUsize {
self.1
}
}
impl ParThreadPool for &mut PondPool {
type ScopeRef<'s, 'env, 'scope>
= Scope<'env, 'scope>
where
'scope: 's,
'env: 'scope + 's;
fn run_in_scope<'s, 'env, 'scope, W>(s: &Self::ScopeRef<'s, 'env, 'scope>, work: W)
where
'scope: 's,
'env: 'scope + 's,
W: Fn() + Send + 'scope + 'env,
{
s.execute(work);
}
fn scoped_computation<'env, 'scope, F>(&'env mut self, f: F)
where
'env: 'scope,
for<'s> F: FnOnce(Scope<'env, 'scope>) + Send,
{
self.0.scoped(f)
}
fn max_num_threads(&self) -> NonZeroUsize {
self.1
}
}