diff options
author | Canop <cano.petrole@gmail.com> | 2020-06-25 22:50:18 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2020-06-25 22:50:18 +0200 |
commit | 1f05df8cd295f00026f96c3003829611041ff305 (patch) | |
tree | 0242ddab1a88a3e35457730f1bb912492c0bf708 /src/file_sum | |
parent | ec9bf7a54cb5a2e8881ef2c503daa798381f2fe7 (diff) |
explicit --whale-spotting launch argument (sort by size, show all files)
Diffstat (limited to 'src/file_sum')
-rw-r--r-- | src/file_sum/sum_computation.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/file_sum/sum_computation.rs b/src/file_sum/sum_computation.rs index 7e46ad2..e8231f2 100644 --- a/src/file_sum/sum_computation.rs +++ b/src/file_sum/sum_computation.rs @@ -2,6 +2,7 @@ use { super::FileSum, crate::task_sync::Dam, crossbeam::channel, + rayon::{ThreadPool, ThreadPoolBuilder}, std::{ convert::TryInto, fs, @@ -10,8 +11,6 @@ use { atomic::{AtomicIsize, Ordering}, Arc, }, - thread, - }, }; @@ -24,7 +23,8 @@ use { }, }; -const THREADS_COUNT: usize = 4; +// threads used by one computation +const THREADS_COUNT: usize = 6; /// compute the consolidated numbers for a directory, with implementation /// varying depending on the OS: @@ -33,6 +33,10 @@ const THREADS_COUNT: usize = 4; pub fn compute_dir_sum(path: &Path, dam: &Dam) -> Option<FileSum> { //debug!("compute size of dir {:?} --------------- ", path); + lazy_static! { + static ref THREAD_POOL: ThreadPool = ThreadPoolBuilder::new().num_threads(THREADS_COUNT*2).build().unwrap(); + } + // to avoid counting twice an inode, we store them in a set #[cfg(unix)] let inodes = Arc::new(Mutex::new(HashSet::<u64>::default())); @@ -61,7 +65,7 @@ pub fn compute_dir_sum(path: &Path, dam: &Dam) -> Option<FileSum> { let observer = dam.observer(); let thread_sum_sender = thread_sum_sender.clone(); - thread::spawn(move || { + THREAD_POOL.spawn(move || { let mut thread_sum = FileSum::zero(); loop { let o = dirs_receiver.recv(); |