Skip to content

Commit

Permalink
feat!: Parallelism::RayonExistingPool::busy_timeout is now optional.
Browse files Browse the repository at this point in the history
That way we can indicate that no waiting should be done as we know the
given threadpool has enough resources.
  • Loading branch information
Byron committed Dec 15, 2022
1 parent c265744 commit 3a71721
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ pub enum Parallelism {
RayonExistingPool {
/// The pool to spawn our work onto.
pool: Arc<ThreadPool>,
/// 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<std::time::Duration>,
},
/// Run in new rayon thread pool with # threads
RayonNewPool(usize),
Expand Down Expand Up @@ -538,8 +539,8 @@ impl Parallelism {
pub(crate) fn timeout(&self) -> Option<std::time::Duration> {
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,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3a71721

Please sign in to comment.