Skip to content

Commit

Permalink
Merge branch 'stalling-issue'
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Dec 13, 2022
2 parents 6a2781c + bd3e880 commit 7bd2f35
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 3 additions & 1 deletion examples/du.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate jwalk;

use jwalk::WalkDirGeneric;
use jwalk::{Parallelism, WalkDirGeneric};
use std::env;

fn main() {
Expand All @@ -9,6 +9,7 @@ fn main() {

for dir_entry_result in WalkDirGeneric::<((), Option<u64>)>::new(&path)
.skip_hidden(false)
.parallelism(Parallelism::RayonNewPool(4))
.process_read_dir(|_, _, _, dir_entry_results| {
dir_entry_results.iter_mut().for_each(|dir_entry_result| {
if let Ok(dir_entry) = dir_entry_result {
Expand All @@ -23,6 +24,7 @@ fn main() {
match dir_entry_result {
Ok(dir_entry) => {
if let Some(len) = &dir_entry.client_state {
eprintln!("counting {:?}", dir_entry.path());
total += len;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,12 @@ impl Parallelism {
thread_pool = thread_pool.num_threads(*num_threads);
}
if let Ok(thread_pool) = thread_pool.build() {
thread_pool.install(op);
thread_pool.spawn(op);
} else {
rayon::spawn(op);
}
}
Parallelism::RayonExistingPool(thread_pool) => thread_pool.install(op),
Parallelism::RayonExistingPool(thread_pool) => thread_pool.spawn(op),
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,6 @@ fn combine_with_rayon_no_lockup_1() {
#[test]
fn combine_with_rayon_no_lockup_2() {
WalkDir::new(PathBuf::from(env!("CARGO_MANIFEST_DIR")))
// lockup if don't use separate rayon pool (old)
// doesn't seem to be a problem now ...
//.parallelism(Parallelism::RayonNewPool(0))
.sort(true)
.into_iter()
.par_bridge()
Expand Down Expand Up @@ -950,7 +947,10 @@ fn walk_file() {
let (test_dir, _temp_dir) = test_dir();
let walk_dir = WalkDir::new(test_dir.join("a.txt"));
let mut iter = walk_dir.into_iter();
assert!(iter.next().unwrap().unwrap().file_name.to_str().unwrap() == "a.txt");
assert_eq!(
iter.next().unwrap().unwrap().file_name.to_str().unwrap(),
"a.txt"
);
assert!(iter.next().is_none());
}

Expand All @@ -959,7 +959,10 @@ fn walk_file_serial() {
let (test_dir, _temp_dir) = test_dir();
let walk_dir = WalkDir::new(test_dir.join("a.txt")).parallelism(Parallelism::Serial);
let mut iter = walk_dir.into_iter();
assert!(iter.next().unwrap().unwrap().file_name.to_str().unwrap() == "a.txt");
assert_eq!(
iter.next().unwrap().unwrap().file_name.to_str().unwrap(),
"a.txt"
);
assert!(iter.next().is_none());
}

Expand Down Expand Up @@ -1011,7 +1014,7 @@ fn walk_root() {
.into_iter()
.filter_map(|each| Some(each.ok()?.path()))
.collect();
assert!(paths.first().unwrap().to_str().unwrap() == "/");
assert_eq!(paths.first().unwrap().to_str().unwrap(), "/");
}

lazy_static! {
Expand Down

0 comments on commit 7bd2f35

Please sign in to comment.