1use std::sync::{Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};
8
9pub fn rwlock_read_or_recover<T>(lock: &RwLock<T>) -> RwLockReadGuard<'_, T> {
11 lock.read().unwrap_or_else(|poisoned| {
12 eprintln!("Warning: recovering from poisoned rwlock (read)");
13 poisoned.into_inner()
14 })
15}
16
17pub fn rwlock_write_or_recover<T>(lock: &RwLock<T>) -> RwLockWriteGuard<'_, T> {
19 lock.write().unwrap_or_else(|poisoned| {
20 eprintln!("Warning: recovering from poisoned rwlock (write)");
21 poisoned.into_inner()
22 })
23}
24
25pub fn mutex_lock_or_recover<T>(lock: &Mutex<T>) -> MutexGuard<'_, T> {
27 lock.lock().unwrap_or_else(|poisoned| {
28 eprintln!("Warning: recovering from poisoned mutex");
29 poisoned.into_inner()
30 })
31}