refactor: move compression engine copy calls to separate threads
This commit is contained in:
26
src/main.rs
26
src/main.rs
@@ -538,14 +538,32 @@ fn mode_diff(cmd: &mut Command, args: Args, ids: &mut Vec<i64>, tags: &mut Vec<S
|
|||||||
|
|
||||||
let stdout_a_raw = unsafe { std::fs::File::from_raw_fd(fd_a_write) };
|
let stdout_a_raw = unsafe { std::fs::File::from_raw_fd(fd_a_write) };
|
||||||
let stdout_b_raw = unsafe { std::fs::File::from_raw_fd(fd_b_write) };
|
let stdout_b_raw = unsafe { std::fs::File::from_raw_fd(fd_b_write) };
|
||||||
let mut stdout_a = BufWriter::new(stdout_a_raw);
|
let stdout_a = BufWriter::new(stdout_a_raw);
|
||||||
let mut stdout_b = BufWriter::new(stdout_b_raw);
|
let stdout_b = BufWriter::new(stdout_b_raw);
|
||||||
|
|
||||||
debug!("MAIN: Sending item A to diff");
|
debug!("MAIN: Sending item A to diff");
|
||||||
compression_engine_a.copy(item_path_a.clone(), &mut stdout_a)?;
|
let handle_a = {
|
||||||
|
let stdout_a = stdout_a.clone();
|
||||||
|
let item_path_a = item_path_a.clone();
|
||||||
|
let compression_engine_a = compression_engine_a.clone();
|
||||||
|
std::thread::spawn(move || {
|
||||||
|
compression_engine_a.copy(item_path_a, &mut stdout_a).unwrap()
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
debug!("MAIN: Sending item B to diff");
|
debug!("MAIN: Sending item B to diff");
|
||||||
compression_engine_b.copy(item_path_b.clone(), &mut stdout_b)?;
|
let handle_b = {
|
||||||
|
let stdout_b = stdout_b.clone();
|
||||||
|
let item_path_b = item_path_b.clone();
|
||||||
|
let compression_engine_b = compression_engine_b.clone();
|
||||||
|
std::thread::spawn(move || {
|
||||||
|
compression_engine_b.copy(item_path_b, &mut stdout_b).unwrap()
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
debug!("MAIN: Done copying data to FDs");
|
debug!("MAIN: Done copying data to FDs");
|
||||||
|
handle_a.join().unwrap();
|
||||||
|
handle_b.join().unwrap();
|
||||||
|
|
||||||
let output = child.wait_with_output().expect("Failed to wait on diff command");
|
let output = child.wait_with_output().expect("Failed to wait on diff command");
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
|
|||||||
Reference in New Issue
Block a user