use parking_lot::Mutex instead of tokio::sync::Mutex

This commit is contained in:
monosans
2025-08-08 09:38:01 +03:00
parent c9fe0ed26e
commit b3b586ae25
4 changed files with 10 additions and 7 deletions
+4 -4
View File
@@ -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!(
+3 -3
View File
@@ -16,7 +16,7 @@ async fn scrape_one(
config: Arc<Config>,
http_client: reqwest::Client,
proto: ProxyType,
proxies: Arc<tokio::sync::Mutex<HashSet<Proxy>>>,
proxies: Arc<parking_lot::Mutex<HashSet<Proxy>>>,
source: Arc<Source>,
#[cfg(feature = "tui")] tx: tokio::sync::mpsc::UnboundedSender<Event>,
) -> 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<Event>,
) -> color_eyre::Result<Vec<Proxy>> {
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 {