chiark / gitweb /
Mutex debug: Actually add some debug messages.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 27 Mar 2022 12:54:15 +0000 (13:54 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 27 Mar 2022 23:50:50 +0000 (00:50 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/debugmutex.rs

index 8caa704c6b0b1545ce957886143913d9b59eb228..da4023c96677bfba1af3a7052aabfb813c9f69b2 100644 (file)
@@ -13,7 +13,10 @@ impl<T> Mutex<T> where T: DebugIdentify {
     Mutex(parking_lot::Mutex::new(t))
   }
   pub fn lock(&self) -> MutexGuard<T> {
-    MutexGuard(self.0.lock())
+    dbg!(dtype::<T>());
+    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<T: DebugIdentify>() -> 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>(C);
 impl<C> Debug for DebugFormatter<C>
 where C: for<'f,'ff> Fn(&'f mut fmt::Formatter<'ff>) -> fmt::Result {