From fff23a4897816cfd40be6d8a1c6ad8c97add9581 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 27 Mar 2022 13:54:15 +0100 Subject: [PATCH] Mutex debug: Actually add some debug messages. Signed-off-by: Ian Jackson --- src/debugmutex.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/debugmutex.rs b/src/debugmutex.rs index 8caa704c..da4023c9 100644 --- a/src/debugmutex.rs +++ b/src/debugmutex.rs @@ -13,7 +13,10 @@ impl Mutex where T: DebugIdentify { Mutex(parking_lot::Mutex::new(t)) } pub fn lock(&self) -> MutexGuard { - MutexGuard(self.0.lock()) + dbg!(dtype::()); + let r = MutexGuard(self.0.lock()); + dbg!(dident(&*r)); + r } } @@ -25,6 +28,19 @@ impl<'g,T> DerefMut for MutexGuard<'g,T> where T: DebugIdentify { fn deref_mut(&mut self) -> &mut T { &mut *self.0 } } +impl<'g,T> Drop for MutexGuard<'g,T> where T: DebugIdentify { + fn drop(&mut self) { + dbg!(dident(&**self)); + } +} + +pub fn dtype() -> impl Debug { + DebugFormatter(T::debug_identify_type) +} +pub fn dident<'t, T: DebugIdentify>(t: &'t T) -> impl Debug + 't { + DebugFormatter(move |f: &'_ mut fmt::Formatter<'_>| t.debug_identify(f)) +} + pub struct DebugFormatter(C); impl Debug for DebugFormatter where C: for<'f,'ff> Fn(&'f mut fmt::Formatter<'ff>) -> fmt::Result { -- 2.30.2