orx_parallel/runner/implementations/
rayon_core.rs

1use crate::par_thread_pool::ParThreadPool;
2use core::num::NonZeroUsize;
3use rayon_core::ThreadPool;
4
5impl ParThreadPool for ThreadPool {
6    type ScopeRef<'s, 'env, 'scope>
7        = &'s rayon_core::Scope<'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.spawn(move |_| 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 rayon_core::Scope<'scope>) + Send,
25    {
26        self.scope(f)
27    }
28
29    fn max_num_threads(&self) -> NonZeroUsize {
30        NonZeroUsize::new(self.current_num_threads().max(1)).expect(">0")
31    }
32}
33
34impl ParThreadPool for &rayon_core::ThreadPool {
35    type ScopeRef<'s, 'env, 'scope>
36        = &'s rayon_core::Scope<'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.spawn(move |_| 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 rayon_core::Scope<'scope>) + Send,
54    {
55        self.scope(f)
56    }
57
58    fn max_num_threads(&self) -> NonZeroUsize {
59        NonZeroUsize::new(self.current_num_threads().max(1)).expect(">0")
60    }
61}