binius_maybe_rayon/
lib.rs1cfg_if::cfg_if! {
14 if #[cfg(any(not(feature = "rayon"), all(target_arch="wasm32", not(target_feature = "atomics"))))] {
15 use std::marker::PhantomData;
16
17 pub mod iter;
18 pub mod slice;
19
20 pub mod prelude {
21 pub use super::{iter::*, slice::*};
22 }
23
24 #[derive(Default)]
25 pub struct ThreadPoolBuilder();
26 impl ThreadPoolBuilder {
27 #[inline(always)]
28 pub const fn new() -> Self {
29 Self()
30 }
31
32 #[inline(always)]
33 pub const fn build(self) -> Result<ThreadPool, ::core::convert::Infallible> {
34 Ok(ThreadPool())
35 }
36
37 #[inline(always)]
38 pub const fn num_threads(self, _num_threads: usize) -> Self {
39 Self()
40 }
41 }
42
43 #[derive(Debug)]
44 pub struct ThreadPool();
45 impl ThreadPool {
46 #[inline(always)]
47 pub fn install<OP, R>(&self, op: OP) -> R
48 where
49 OP: FnOnce() -> R + Send,
50 R: Send,
51 {
52 op()
53 }
54 }
55
56 #[derive(Debug, Default)]
57 pub struct ThreadPoolBuildError;
58 impl std::fmt::Display for ThreadPoolBuildError {
59 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
60 write!(f, "ThreadPoolBuildError")
61 }
62 }
63 impl std::error::Error for ThreadPoolBuildError {
64 fn description(&self) -> &str {
65 "Error building thread pool"
66 }
67 }
68
69 #[inline(always)]
70 pub const fn current_num_threads() -> usize {
71 1
72 }
73
74 #[inline(always)]
75 pub fn join<A, B, RA, RB>(oper_a: A, oper_b: B) -> (RA, RB)
76 where
77 A: FnOnce() -> RA + Send,
78 B: FnOnce() -> RB + Send,
79 RA: Send,
80 RB: Send,
81 {
82 (oper_a(), oper_b())
83 }
84
85 pub struct Scope<'scope> {
86 #[allow(clippy::type_complexity)]
87 marker: PhantomData<Box<dyn FnOnce(&Scope<'scope>) + Send + Sync + 'scope>>,
88 }
89
90 impl<'scope> Scope<'scope> {
91 #[inline(always)]
92 pub fn spawn<BODY>(&self, body: BODY)
93 where
94 BODY: FnOnce(&Self) + Send + 'scope,
95 {
96 body(self)
97 }
98 }
99
100 #[inline(always)]
101 pub fn scope<'scope, OP, R>(op: OP) -> R
102 where
103 OP: for<'s> FnOnce(&'s Scope<'scope>) -> R + 'scope + Send,
104 R: Send,
105 {
106 op(&Scope {
107 marker: PhantomData,
108 })
109 }
110 } else {
111 pub use rayon::*;
112 }
113}