orx_parallel/runner/implementations/
poolite.rs

1use crate::par_thread_pool::ParThreadPool;
2use core::num::NonZeroUsize;
3use poolite::{Pool, Scoped};
4
5impl ParThreadPool for Pool {
6    type ScopeRef<'s, 'env, 'scope>
7        = &'s Scoped<'env, 'scope>
8    where
9        'scope: 's,
10        'env: 'scope + 's;
11
12    fn run_in_scope<'s, 'env, 'scope, W>(s: &Self::ScopeRef<'s, 'env, 'scope>, work: W)
13    where
14        'scope: 's,
15        'env: 'scope + 's,
16        W: Fn() + Send + 'scope + 'env,
17    {
18        s.push(work);
19    }
20
21    fn scoped_computation<'env, 'scope, F>(&'env mut self, f: F)
22    where
23        'env: 'scope,
24        for<'s> F: FnOnce(&'s Scoped<'env, 'scope>) + Send,
25    {
26        self.scoped(f);
27    }
28
29    fn max_num_threads(&self) -> NonZeroUsize {
30        NonZeroUsize::new(self.threads_future().max(1)).expect(">0")
31    }
32}
33
34impl ParThreadPool for &Pool {
35    type ScopeRef<'s, 'env, 'scope>
36        = &'s Scoped<'env, 'scope>
37    where
38        'scope: 's,
39        'env: 'scope + 's;
40
41    fn run_in_scope<'s, 'env, 'scope, W>(s: &Self::ScopeRef<'s, 'env, 'scope>, work: W)
42    where
43        'scope: 's,
44        'env: 'scope + 's,
45        W: Fn() + Send + 'scope + 'env,
46    {
47        s.push(work);
48    }
49
50    fn scoped_computation<'env, 'scope, F>(&'env mut self, f: F)
51    where
52        'env: 'scope,
53        for<'s> F: FnOnce(&'s Scoped<'env, 'scope>) + Send,
54    {
55        self.scoped(f);
56    }
57
58    fn max_num_threads(&self) -> NonZeroUsize {
59        NonZeroUsize::new(self.threads_future().max(1)).expect(">0")
60    }
61}