reifydb_runtime/pool/
compute.rs1use std::sync::Arc;
5
6use rayon::{ThreadPool, ThreadPoolBuilder};
7
8pub struct ComputePool {
9 pool: Arc<ThreadPool>,
10}
11
12impl ComputePool {
13 pub(crate) fn new(threads: usize, name_prefix: &'static str) -> Self {
14 Self {
15 pool: Arc::new(
16 ThreadPoolBuilder::new()
17 .num_threads(threads)
18 .thread_name(move |i| format!("{name_prefix}-{i}"))
19 .build()
20 .unwrap_or_else(|_| panic!("failed to build {name_prefix} thread pool")),
21 ),
22 }
23 }
24
25 pub fn install<OP, R>(&self, op: OP) -> R
26 where
27 OP: FnOnce() -> R + Send,
28 R: Send,
29 {
30 self.pool.install(op)
31 }
32
33 pub fn thread_count(&self) -> usize {
34 self.pool.current_num_threads()
35 }
36}