From 7b7dcb5a77061cb69d368de263a02b5ad26fbf51 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 26 Oct 2026 04:20:52 +0100 Subject: unify lock logic --- src/swarm/source.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'src/swarm/source.rs') diff --git a/src/swarm/source.rs b/src/swarm/source.rs index b1701b3..e7f06fb 100644 --- a/src/swarm/source.rs +++ b/src/swarm/source.rs @@ -35,6 +35,7 @@ use std::time::Duration; use tokio::time::Instant; use tracing::{debug, info, warn}; +use crate::locks::MutexExt; use crate::state::{AppState, CatchUpSource, PeerState}; use crate::swarm::sync::SyncEvent; @@ -55,17 +56,11 @@ const REPLY_TIMEOUTS: u32 = 3; const STALL_WARNING: Duration = Duration::from_secs(60); fn lock_preference(state: &AppState) -> std::sync::MutexGuard<'_, Option> { - state - .catch_up_preference - .lock() - .unwrap_or_else(|poisoned| poisoned.into_inner()) + state.catch_up_preference.lock_or_recover() } fn lock_avoided(state: &AppState) -> std::sync::MutexGuard<'_, Option<(String, Instant)>> { - state - .catch_up_avoided - .lock() - .unwrap_or_else(|poisoned| poisoned.into_inner()) + state.catch_up_avoided.lock_or_recover() } fn catching_up(state: &AppState) -> bool { @@ -73,10 +68,7 @@ fn catching_up(state: &AppState) -> bool { } fn lock(state: &AppState) -> std::sync::MutexGuard<'_, Option> { - state - .catch_up_source - .lock() - .unwrap_or_else(|poisoned| poisoned.into_inner()) + state.catch_up_source.lock_or_recover() } /// Returns how long to hold back sync with `peer`, if at all: while catching up, with -- cgit v1.3.1