orx-parallel 3.4.0

High performance, configurable and expressive parallel computation library.
Documentation
use crate::par_thread_pool::ParThreadPool;
use core::num::NonZeroUsize;
use poolite::{Pool, Scoped};

impl ParThreadPool for Pool {
    type ScopeRef<'s, 'env, 'scope>
        = &'s Scoped<'env, 'scope>
    where
        'scope: 's,
        'env: 'scope + 's;

    fn run_in_scope<'s, 'env, 'scope, W>(s: &Self::ScopeRef<'s, 'env, 'scope>, work: W)
    where
        'scope: 's,
        'env: 'scope + 's,
        W: Fn() + Send + 'scope + 'env,
    {
        s.push(work);
    }

    fn scoped_computation<'env, 'scope, F>(&'env mut self, f: F)
    where
        'env: 'scope,
        for<'s> F: FnOnce(&'s Scoped<'env, 'scope>) + Send,
    {
        self.scoped(f);
    }

    fn max_num_threads(&self) -> NonZeroUsize {
        NonZeroUsize::new(self.threads_future().max(1)).expect(">0")
    }
}

impl ParThreadPool for &Pool {
    type ScopeRef<'s, 'env, 'scope>
        = &'s Scoped<'env, 'scope>
    where
        'scope: 's,
        'env: 'scope + 's;

    fn run_in_scope<'s, 'env, 'scope, W>(s: &Self::ScopeRef<'s, 'env, 'scope>, work: W)
    where
        'scope: 's,
        'env: 'scope + 's,
        W: Fn() + Send + 'scope + 'env,
    {
        s.push(work);
    }

    fn scoped_computation<'env, 'scope, F>(&'env mut self, f: F)
    where
        'env: 'scope,
        for<'s> F: FnOnce(&'s Scoped<'env, 'scope>) + Send,
    {
        self.scoped(f);
    }

    fn max_num_threads(&self) -> NonZeroUsize {
        NonZeroUsize::new(self.threads_future().max(1)).expect(">0")
    }
}