From: Ian Jackson Date: Sun, 27 Mar 2022 12:54:15 +0000 (+0100) Subject: Mutex debug: Actually add some debug messages. X-Git-Tag: otter-1.0.0~103 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=fff23a4897816cfd40be6d8a1c6ad8c97add9581;p=otter.git Mutex debug: Actually add some debug messages. Signed-off-by: Ian Jackson --- 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 {