Skip to content
Myr

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

1 file+20 added−25 removed

modified:src/walk.rs+20 added-25 removed
107 unmodified lines
108109 let parallel_walker = walker.threads(threads).build_parallel();110111 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 }119120 // 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);122123 // 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);125126 // Wait for the receiver thread to print out all results.127 receiver_thread.join().unwrap();128
2 unmodified lines
131 }132}133134fn 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);141142 let show_filesystem_errors = config.show_filesystem_errors;143 let threads = config.threads;144145 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 lines
186 // Start in buffering mode187 let mut mode = ReceiverMode::Buffering;188189 // 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));193194 let stdout = io::stdout();
14 unmodified lines
209 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 line
220 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 lines
237 // 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}247248fn 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);260261 Box::new(move |entry_o| {262 if wants_to_quit.load(Ordering::Relaxed) {263 return ignore::WalkState::Quit;
116 unmodified lines