Uniform names for config and wants_to_quit. Pass Arc's by ref.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Alexandru Macovei · committed by David Peter · parent 5ade72a · Browse files · 1 file·+20 added−25 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+20 added−25 removed
- other:+20 added−25 removed
Provenance
- Commit
df4227c- Tree
7c7d3ac- Author
Alexandru Macovei <alexnmaco@gmail.com>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
5ade72a
1 file changed+20 added−25 removed
modified:src/walk.rs+20 added-25 removed
107 unmodified lines108 109 let parallel_walker = walker.threads(threads).build_parallel();110 111 let wants_to_quit = Arc::new(AtomicBool::new(false));112- let receiver_wtq = Arc::clone(&wants_to_quit);113- let sender_wtq = Arc::clone(&wants_to_quit);112 if config.ls_colors.is_some() && config.command.is_none() {115- let wq = Arc::clone(&receiver_wtq);113+ let wq = Arc::clone(&wants_to_quit);114 ctrlc::set_handler(move || {115 wq.store(true, Ordering::Relaxed);116 })117 .unwrap();118 }119 120 // Spawn the thread that receives all results through the channel.123- let receiver_thread = spawn_receiver(Arc::clone(&config), receiver_wtq, rx);121+ let receiver_thread = spawn_receiver(&config, &wants_to_quit, rx);122 123 // Spawn the sender threads.126- spawn_senders(127- Arc::clone(&config),128- pattern,129- sender_wtq,130- parallel_walker,131- tx,132- );124+ spawn_senders(&config, &wants_to_quit, pattern, parallel_walker, tx);125 126 // Wait for the receiver thread to print out all results.127 receiver_thread.join().unwrap();128 2 unmodified lines131 }132 }133 134 fn spawn_receiver(143- rx_config: Arc<FdOptions>,144- receiver_wtq: Arc<AtomicBool>,135+ config: &Arc<FdOptions>,136+ wants_to_quit: &Arc<AtomicBool>,137 rx: Receiver<WorkerResult>,138 ) -> thread::JoinHandle<()> {147- let show_filesystem_errors = rx_config.show_filesystem_errors;148- let threads = rx_config.threads;139+ let config = Arc::clone(config);140+ let wants_to_quit = Arc::clone(wants_to_quit);141 142+ let show_filesystem_errors = config.show_filesystem_errors;143+ let threads = config.threads;144+145 thread::spawn(move || {146 // This will be set to `Some` if the `--exec` argument was supplied.152- if let Some(ref cmd) = rx_config.command {147+ if let Some(ref cmd) = config.command {148 if cmd.in_batch_mode() {149 exec::batch(rx, cmd, show_filesystem_errors);150 } else {151 let shared_rx = Arc::new(Mutex::new(rx));34 unmodified lines186 // Start in buffering mode187 let mut mode = ReceiverMode::Buffering;188 189 // Maximum time to wait before we start streaming to the console.195- let max_buffer_time = rx_config190+ let max_buffer_time = config191 .max_buffer_time192 .unwrap_or_else(|| time::Duration::from_millis(100));193 194 let stdout = io::stdout();14 unmodified lines209 for v in &buffer {210 output::print_entry(211 &mut stdout,212 v,218- &rx_config,219- &receiver_wtq,213+ &config,214+ &wants_to_quit,215 );216 }217 buffer.clear();218 1 unmodified line220 mode = ReceiverMode::Streaming;221 }222 }223 ReceiverMode::Streaming => {229- output::print_entry(&mut stdout, &value, &rx_config, &receiver_wtq);224+ output::print_entry(&mut stdout, &value, &config, &wants_to_quit);225 }226 }227 }228 WorkerResult::Error(err) => {8 unmodified lines237 // anything to the console, yet. In this case, sort the results and print them:238 if !buffer.is_empty() {239 buffer.sort();240 for value in buffer {246- output::print_entry(&mut stdout, &value, &rx_config, &receiver_wtq);241+ output::print_entry(&mut stdout, &value, &config, &wants_to_quit);242 }243 }244 }245 })246 }247 248 fn spawn_senders(254- config: Arc<FdOptions>,249+ config: &Arc<FdOptions>,250+ wants_to_quit: &Arc<AtomicBool>,251 pattern: Arc<Regex>,256- sender_wtq: Arc<AtomicBool>,252 parallel_walker: ignore::WalkParallel,253 tx: Sender<WorkerResult>,254 ) {255 parallel_walker.run(|| {261- let config = Arc::clone(&config);256+ let config = Arc::clone(config);257 let pattern = Arc::clone(&pattern);258 let tx_thread = tx.clone();264- let wants_to_quit = Arc::clone(&sender_wtq);259+ let wants_to_quit = Arc::clone(wants_to_quit);260 261 Box::new(move |entry_o| {262 if wants_to_quit.load(Ordering::Relaxed) {263 return ignore::WalkState::Quit;116 unmodified lines