From 77b01d170fdecf933c236625b3552c21c0c1e45a Mon Sep 17 00:00:00 2001 From: ttyS3 Date: Mon, 2 Dec 2024 12:49:19 +0000 Subject: [PATCH] refactor(cli): move thread pool setup to command execution, use thread::spawn instead of rayon::spawn in the logger thread --- src/cli/mod.rs | 7 ------- src/commands/mod.rs | 8 ++++++++ src/utils/logger.rs | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 4144e53..ce6b5d5 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -28,13 +28,6 @@ impl CliArgs { set_accessible(args.accessible); - if let Some(threads) = args.threads { - rayon::ThreadPoolBuilder::new() - .num_threads(threads) - .build_global() - .unwrap(); - } - let (Subcommand::Compress { files, .. } | Subcommand::Decompress { files, .. } | Subcommand::List { archives: files, .. }) = &mut args.cmd; diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 97410d7..9baf666 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -53,6 +53,14 @@ pub fn run( question_policy: QuestionPolicy, file_visibility_policy: FileVisibilityPolicy, ) -> crate::Result<()> { + + if let Some(threads) = args.threads { + rayon::ThreadPoolBuilder::new() + .num_threads(threads) + .build_global() + .unwrap(); + } + match args.cmd { Subcommand::Compress { files, diff --git a/src/utils/logger.rs b/src/utils/logger.rs index 5156308..60936c6 100644 --- a/src/utils/logger.rs +++ b/src/utils/logger.rs @@ -1,4 +1,5 @@ use std::sync::{mpsc, Arc, Barrier, OnceLock}; +use std::thread; pub use logger_thread::spawn_logger_thread; @@ -168,7 +169,7 @@ mod logger_thread { pub fn spawn_logger_thread() { let log_receiver = setup_channel(); - rayon::spawn(move || run_logger(log_receiver)); + thread::spawn(move || run_logger(log_receiver)); } fn run_logger(log_receiver: LogReceiver) { -- 2.11.4.GIT