From a4bb734482c7bf3fd4d30081e7d3ce7786a3775e Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 1 Dec 2021 10:24:58 -0500 Subject: [PATCH] Switch from std::sync::mpsc to crossbeam-channel This lets us avoid https://github.com/rust-lang/rust/issues/39364, which could potentially be seen now that we're using recv_timeout(). --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + src/exec/job.rs | 3 ++- src/walk.rs | 10 +++------- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4cc7fcf..045040a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -108,6 +108,16 @@ dependencies = [ "vec_map", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.5" @@ -164,6 +174,7 @@ dependencies = [ "atty", "chrono", "clap", + "crossbeam-channel", "ctrlc", "diff", "dirs-next", diff --git a/Cargo.toml b/Cargo.toml index e8f2129..e648b9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,6 +49,7 @@ dirs-next = "2.0" normpath = "0.3" chrono = "0.4" once_cell = "1.8.0" +crossbeam-channel = "0.5.1" [dependencies.clap] version = "2.31.3" diff --git a/src/exec/job.rs b/src/exec/job.rs index 85b30f1..0effc44 100644 --- a/src/exec/job.rs +++ b/src/exec/job.rs @@ -1,7 +1,8 @@ use std::path::PathBuf; -use std::sync::mpsc::Receiver; use std::sync::{Arc, Mutex}; +use crossbeam_channel::Receiver; + use crate::error::print_error; use crate::exit_codes::{merge_exitcodes, ExitCode}; use crate::walk::WorkerResult; diff --git a/src/walk.rs b/src/walk.rs index 244604b..151d568 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -4,13 +4,13 @@ use std::io; use std::mem; use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender}; use std::sync::{Arc, Mutex}; use std::thread; use std::time::{Duration, Instant}; use std::{borrow::Cow, io::Write}; use anyhow::{anyhow, Result}; +use crossbeam_channel::{unbounded, Receiver, RecvTimeoutError, Sender}; use ignore::overrides::OverrideBuilder; use ignore::{self, WalkBuilder}; use once_cell::unsync::OnceCell; @@ -55,7 +55,7 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) -> R let first_path_buf = path_iter .next() .expect("Error: Path vector can not be empty"); - let (tx, rx) = channel(); + let (tx, rx) = unbounded(); let mut override_builder = OverrideBuilder::new(first_path_buf.as_path()); @@ -219,11 +219,7 @@ impl ReceiverBuffer { match self.mode { ReceiverMode::Buffering => { // Wait at most until we should switch to streaming - let now = Instant::now(); - self.deadline - .checked_duration_since(now) - .ok_or(RecvTimeoutError::Timeout) - .and_then(|t| self.rx.recv_timeout(t)) + self.rx.recv_deadline(self.deadline) } ReceiverMode::Streaming => { // Wait however long it takes for a result