#![allow(dead_code)]
use std::sync::OnceLock;
use strided_basic::{Exec, Pool};
pub fn shared_pool() -> &'static Pool {
static POOL: OnceLock<Pool> = OnceLock::new();
POOL.get_or_init(|| {
Pool::builder()
.dispatch_costs(cheap_dispatch_costs())
.threads(4)
.build()
.unwrap()
})
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Budget {
Serial,
Pooled(usize),
}
impl Budget {
pub fn exec(self) -> Exec<'static> {
match self {
Budget::Serial => Exec::serial(),
Budget::Pooled(n) => Exec::new(shared_pool(), n).unwrap(),
}
}
}
fn cheap_dispatch_costs() -> threadteam::DispatchCosts {
use threadteam::{DispatchKind, WidthCosts};
let cheap = WidthCosts::flat(std::time::Duration::from_nanos(100));
threadteam::DispatchCosts::for_class(threadteam::HostClass::Generic)
.with(DispatchKind::Team, cheap)
.with(DispatchKind::InPool, cheap)
.with(DispatchKind::Outside, cheap)
}