From b3b586ae25cf54f9a4bb26edc62cd7fe366add1e Mon Sep 17 00:00:00 2001 From: monosans Date: Fri, 8 Aug 2025 09:38:01 +0300 Subject: [PATCH] use parking_lot::Mutex instead of tokio::sync::Mutex --- Cargo.lock | 1 + Cargo.toml | 2 ++ src/checker.rs | 8 ++++---- src/scraper.rs | 6 +++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0c60e9b..0246df2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1334,6 +1334,7 @@ dependencies = [ "futures", "httpdate", "maxminddb", + "parking_lot", "rand 0.9.2", "ratatui", "reqwest", diff --git a/Cargo.toml b/Cargo.toml index 8b665d7..709937b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ fancy-regex = "=0.16.1" futures = { version = "=0.3.31", optional = true } httpdate = "=1.0.3" maxminddb = { version = "=0.26.0", features = ["mmap"] } +parking_lot = "=0.12.4" rand = "=0.9.2" ratatui = { version = "=0.29.0", optional = true } rlimit = "=0.10.2" @@ -62,3 +63,4 @@ reqwest = { version = "=0.12.22", default-features = false, features = [ strip = true lto = "fat" codegen-units = 1 +panic = "abort" diff --git a/src/checker.rs b/src/checker.rs index b181b66..2b6f326 100644 --- a/src/checker.rs +++ b/src/checker.rs @@ -25,8 +25,8 @@ pub async fn check_all( #[cfg(not(feature = "tui"))] tracing::info!("Started checking {} proxies", proxies.len()); - let queue = Arc::new(tokio::sync::Mutex::new(proxies)); - let checked_proxies = Arc::new(tokio::sync::Mutex::new(Vec::new())); + let queue = Arc::new(parking_lot::Mutex::new(proxies)); + let checked_proxies = Arc::new(parking_lot::Mutex::new(Vec::new())); let mut join_set = tokio::task::JoinSet::<()>::new(); for _ in 0..workers_count { @@ -41,7 +41,7 @@ pub async fn check_all( biased; res = async move { loop { - let Some(mut proxy) = queue.lock().await.pop() else { + let Some(mut proxy) = queue.lock().pop() else { break; }; let check_result = proxy.check(&config).await; @@ -55,7 +55,7 @@ pub async fn check_all( drop(tx.send(Event::App(AppEvent::ProxyWorking( proxy.protocol, )))); - checked_proxies.lock().await.push(proxy); + checked_proxies.lock().push(proxy); } Err(e) if tracing::event_enabled!( diff --git a/src/scraper.rs b/src/scraper.rs index d66bd8c..c3a7b87 100644 --- a/src/scraper.rs +++ b/src/scraper.rs @@ -16,7 +16,7 @@ async fn scrape_one( config: Arc, http_client: reqwest::Client, proto: ProxyType, - proxies: Arc>>, + proxies: Arc>>, source: Arc, #[cfg(feature = "tui")] tx: tokio::sync::mpsc::UnboundedSender, ) -> color_eyre::Result<()> { @@ -73,7 +73,7 @@ async fn scrape_one( #[cfg(feature = "tui")] let mut seen_protocols = HashSet::new(); - let mut proxies = proxies.lock().await; + let mut proxies = proxies.lock(); for capture in matches { let protocol = match capture.name("protocol") { Some(m) => m.as_str().parse()?, @@ -120,7 +120,7 @@ pub async fn scrape_all( token: tokio_util::sync::CancellationToken, #[cfg(feature = "tui")] tx: tokio::sync::mpsc::UnboundedSender, ) -> color_eyre::Result> { - let proxies = Arc::new(tokio::sync::Mutex::new(HashSet::new())); + let proxies = Arc::new(parking_lot::Mutex::new(HashSet::new())); let mut join_set = tokio::task::JoinSet::new(); for (&proto, sources) in &config.scraping.sources {