diff options
| author | tv <tv@krebsco.de> | 2026-10-26 04:20:52 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-26 04:20:52 +0100 |
| commit | 7b7dcb5a77061cb69d368de263a02b5ad26fbf51 (patch) | |
| tree | d3255ce629cb60059cb55191dc206d0f64ca645e /src/swarm/source.rs | |
| parent | d668ce2ff8f308e54c1c7a2c145cb3479cab899d (diff) | |
unify lock logic
Diffstat (limited to 'src/swarm/source.rs')
| -rw-r--r-- | src/swarm/source.rs | 16 |
1 files changed, 4 insertions, 12 deletions
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<Instant>> { - 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<CatchUpSource>> { - 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 |
