From 3a717219411a7478b90c4d694d57e28d8941dde1 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 15 Dec 2022 13:23:03 +0100 Subject: [PATCH] feat!: `Parallelism::RayonExistingPool::busy_timeout` is now optional. That way we can indicate that no waiting should be done as we know the given threadpool has enough resources. --- src/lib.rs | 9 +++++---- tests/integration.rs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 299fe03..2b5e26f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -189,8 +189,9 @@ pub enum Parallelism { RayonExistingPool { /// The pool to spawn our work onto. pool: Arc, - /// Similar to [`Parallelism::RayonDefaultPool::busy_timeout`]. - busy_timeout: std::time::Duration, + /// Similar to [`Parallelism::RayonDefaultPool::busy_timeout`] if `Some`, but can be `None` to skip the deadlock check + /// in case you know that there is at least one free thread available on the pool. + busy_timeout: Option, }, /// Run in new rayon thread pool with # threads RayonNewPool(usize), @@ -538,8 +539,8 @@ impl Parallelism { pub(crate) fn timeout(&self) -> Option { match self { Parallelism::Serial | Parallelism::RayonNewPool(_) => None, - Parallelism::RayonDefaultPool { busy_timeout } - | Parallelism::RayonExistingPool { busy_timeout, .. } => Some(*busy_timeout), + Parallelism::RayonDefaultPool { busy_timeout } => Some(*busy_timeout), + Parallelism::RayonExistingPool { busy_timeout, .. } => *busy_timeout, } } } diff --git a/tests/integration.rs b/tests/integration.rs index bcb36ec..13017f7 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -892,7 +892,7 @@ fn walk_rayon_no_lockup() { let _: Vec<_> = WalkDir::new(PathBuf::from(env!("CARGO_MANIFEST_DIR"))) .parallelism(Parallelism::RayonExistingPool { pool, - busy_timeout: std::time::Duration::from_millis(500), + busy_timeout: std::time::Duration::from_millis(500).into(), }) .process_read_dir(|_, _, _, dir_entry_results| { for dir_entry_result in dir_entry_results {