src/parallelism.rs

branch
dev
changeset 45
ad1f3705c3fc
parent 8
4e09b7829b51
--- a/src/parallelism.rs	Fri Oct 13 14:15:56 2023 -0500
+++ b/src/parallelism.rs	Wed Oct 30 14:22:06 2024 -0500
@@ -16,9 +16,9 @@
     Ordering::{Release, Relaxed},
 };
 
-#[cfg(use_custom_thread_pool)]
+#[cfg(feature = "use_custom_thread_pool")]
 type Pool = ThreadPool;
-#[cfg(not(use_custom_thread_pool))]
+#[cfg(not(feature = "use_custom_thread_pool"))]
 type Pool = GlobalPool;
 
 const ONE : NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(1) };
@@ -27,12 +27,12 @@
 static mut POOL : Option<Pool> = None;
 static INIT: Once = Once::new();
 
-#[cfg(not(use_custom_thread_pool))]
+#[cfg(not(feature = "use_custom_thread_pool"))]
 mod global_pool {
     /// This is a nicer way to use the global pool of [`rayon`].
     pub struct GlobalPool;
 
-    #[cfg(not(use_custom_thread_pool))]
+    #[cfg(not(feature = "use_custom_thread_pool"))]
     impl GlobalPool {
         #[inline]
         pub fn scope<'scope, OP, R>(&self, op: OP) -> R
@@ -44,7 +44,7 @@
     }
 }
 
-#[cfg(not(use_custom_thread_pool))]
+#[cfg(not(feature = "use_custom_thread_pool"))]
 pub use global_pool::GlobalPool;
 
 /// Set the number of threads.
@@ -57,10 +57,10 @@
         let n = n.get();
         set_task_overbudgeting((n + 1) / 2);
         POOL = if n > 1 {
-            #[cfg(use_custom_thread_pool)] {
+            #[cfg(feature = "use_custom_thread_pool")] {
                 Some(ThreadPoolBuilder::new().num_threads(n).build().unwrap())
             }
-            #[cfg(not(use_custom_thread_pool))] {
+            #[cfg(not(feature = "use_custom_thread_pool"))] {
                 ThreadPoolBuilder::new().num_threads(n).build_global().unwrap();
                 Some(GlobalPool)
             }
@@ -75,6 +75,7 @@
 /// The initial value is 1. Calling [`set_num_threads`] sets this to  $m = (n + 1) / 2$, where
 /// $n$ is the number of threads.
 pub fn set_task_overbudgeting(m : usize) {
+    #[allow(static_mut_refs)]
     unsafe { TASK_OVERBUDGETING.store(m, Relaxed) }
 }
 
@@ -97,6 +98,7 @@
 /// If the number of configured threads is less than 2, this is None.
 /// The pool has [`num_threads`]` - 1` threads.
 pub fn thread_pool() -> Option<&'static Pool> {
+    #[allow(static_mut_refs)]
     unsafe { POOL.as_ref() }
 }
 
@@ -146,6 +148,7 @@
     /// is `None`, the [global setting][set_task_overbudgeting] is used.ยง
     pub fn init(overbudget : Option<usize>) -> Self {
         let n = num_threads().get();
+        #[allow(static_mut_refs)]
         let m = overbudget.unwrap_or_else(|| unsafe { TASK_OVERBUDGETING.load(Relaxed) });
         if n <= 1 {
             Self::SingleThreaded

mercurial