Skip to content
Myr

split spawn_receiver(..) and spawn_senders(..) from scan(..).

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This is just a split commit, refraining from renaming too much. The drop(tx) call is no longer necessary, as the first sender is dropped at the end of spawn_senders(..)

authored by Alexandru Macovei · committed by David Peter · parent d8bd5f9 · Browse files · 1 file+38 added−17 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+38 added−17 removed

  • other:+38 added−17 removed

1 file+38 added−17 removed

modified:src/walk.rs+38 added-17 removed
15 unmodified lines
16use std::io;17use std::path::PathBuf;18use std::process;19use std::sync::atomic::{AtomicBool, Ordering};20use std::sync::mpsc::channel;20use std::sync::mpsc::{channel, Receiver, Sender};21use std::sync::{Arc, Mutex};22use std::thread;23use std::time;24
28 unmodified lines
53 .next()54 .expect("Error: Path vector can not be empty");55 let (tx, rx) = channel();56 let threads = config.threads;57 let show_filesystem_errors = config.show_filesystem_errors;5758 let mut override_builder = OverrideBuilder::new(first_path_buf.as_path());5960 for pattern in &config.exclude_patterns {
58 unmodified lines
119 .unwrap();120 }121122 // Spawn the thread that receives all results through the channel.124 let rx_config = Arc::clone(&config);125 let receiver_thread = thread::spawn(move || {123 let receiver_thread = spawn_receiver(Arc::clone(&config), receiver_wtq, rx);124125 // Spawn the sender threads.126 spawn_senders(127 Arc::clone(&config),128 pattern,129 sender_wtq,130 parallel_walker,131 tx,132 );133134 // Wait for the receiver thread to print out all results.135 receiver_thread.join().unwrap();136137 if wants_to_quit.load(Ordering::Relaxed) {138 process::exit(ExitCode::KilledBySigint.into());139 }140}141142fn spawn_receiver(143 rx_config: Arc<FdOptions>,144 receiver_wtq: Arc<AtomicBool>,145 rx: Receiver<WorkerResult>,146) -> thread::JoinHandle<()> {147 let show_filesystem_errors = rx_config.show_filesystem_errors;148 let threads = rx_config.threads;149150 thread::spawn(move || {151 // This will be set to `Some` if the `--exec` argument was supplied.152 if let Some(ref cmd) = rx_config.command {153 if cmd.in_batch_mode() {154 exec::batch(rx, cmd, show_filesystem_errors);
91 unmodified lines
246 output::print_entry(&mut stdout, &value, &rx_config, &receiver_wtq);247 }248 }249 }225 });250 })251}252227 // Spawn the sender threads.253fn spawn_senders(254 config: Arc<FdOptions>,255 pattern: Arc<Regex>,256 sender_wtq: Arc<AtomicBool>,257 parallel_walker: ignore::WalkParallel,258 tx: Sender<WorkerResult>,259) {260 parallel_walker.run(|| {261 let config = Arc::clone(&config);262 let pattern = Arc::clone(&pattern);263 let tx_thread = tx.clone();
116 unmodified lines
380381 ignore::WalkState::Continue382 })383 });352353 // Drop the initial sender. If we don't do this, the receiver will block even354 // if all threads have finished, since there is still one sender around.355 drop(tx);356357 // Wait for the receiver thread to print out all results.358 receiver_thread.join().unwrap();359360 if wants_to_quit.load(Ordering::Relaxed) {361 process::exit(ExitCode::KilledBySigint.into());362 }384}