Skip to content

Commit

Permalink
refactor(cli): move thread pool setup to command execution, use threa…
Browse files Browse the repository at this point in the history
…d::spawn instead of rayon::spawn in the logger thread
  • Loading branch information
ttys3 committed Dec 2, 2024
1 parent 221084b commit bf676ef
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
7 changes: 0 additions & 7 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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,
Expand Down
3 changes: 2 additions & 1 deletion src/utils/logger.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::sync::{mpsc, Arc, Barrier, OnceLock};
use std::thread;

pub use logger_thread::spawn_logger_thread;

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit bf676ef

Please sign in to comment.