#![allow(dead_code)]
#[cfg(feature = "parallel")]
use rayon::ThreadPool;
#[cfg(feature = "parallel")]
use std::sync::OnceLock;
#[cfg(feature = "parallel")]
static THREAD_POOL: OnceLock<ThreadPool> = OnceLock::new();
#[cfg(feature = "parallel")]
pub fn get_thread_pool() -> &'static ThreadPool {
THREAD_POOL.get_or_init(|| {
rayon::ThreadPoolBuilder::new()
.stack_size(8 * 1024 * 1024) .build()
.expect("Failed to build custom thread pool")
})
}
#[cfg(feature = "parallel")]
pub fn install<OP, R>(op: OP) -> R
where
OP: FnOnce() -> R + Send,
R: Send,
{
get_thread_pool().install(op)
}
#[cfg(not(feature = "parallel"))]
pub fn install<OP, R>(op: OP) -> R
where
OP: FnOnce() -> R,
{
op()
}