use crate::query::fold::fold_policy;
use crate::query::types::ReadPlan;
pub(crate) fn with_fold_workers<R>(workers: Option<usize>, f: impl FnOnce() -> R + Send) -> R
where
R: Send,
{
if let Some(n) = workers.filter(|&n| n > 0 && n < rayon::current_num_threads()) {
rayon::ThreadPoolBuilder::new()
.num_threads(n)
.build()
.expect("fold rayon pool")
.install(f)
} else {
f()
}
}
#[must_use]
pub(crate) fn use_parallel_fold(plan: &ReadPlan, policy: &fold_policy::FoldIoPolicy) -> bool {
!policy.linear_scan && policy.parallel && plan.chunks.len() > 1
}