use parking_lot::Mutex;
use parking_lot::MutexGuard;
pub struct DebugMutex<T> {
name: &'static str,
mtx: Mutex<T>,
}
impl<T> DebugMutex<T> {
pub fn new(inner: T, name: &'static str) -> Self {
DebugMutex {
mtx: Mutex::new(inner),
name,
}
}
pub fn lock(&self, reason: &'static str) -> anyhow::Result<MutexGuard<'_, T>> {
log::trace!(
"lock mutex:{} for: {} from thread: {}",
self.name,
reason,
thread_id::get()
);
let ret = self.mtx.lock();
log::trace!(
"locked mutex:{} for: {} from thread: {}",
self.name,
reason,
thread_id::get()
);
Ok(ret)
}
}