From: Ian Jackson Date: Sun, 27 Mar 2022 11:46:54 +0000 (+0100) Subject: Mutex debug: Introduce Mutex and guard types X-Git-Tag: otter-1.0.0~108 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=12db97a0d3f74d801ad6273e353547f215b341fc;p=otter.git Mutex debug: Introduce Mutex and guard types Signed-off-by: Ian Jackson --- diff --git a/src/debugmutex.rs b/src/debugmutex.rs new file mode 100644 index 00000000..a9960fe8 --- /dev/null +++ b/src/debugmutex.rs @@ -0,0 +1,25 @@ + +use crate::prelude::*; + +#[derive(Debug, Default)] +pub struct Mutex(parking_lot::Mutex); + +#[derive(Debug, Display)] +pub struct MutexGuard<'g, T>(parking_lot::MutexGuard<'g, T>); + +impl Mutex { + pub fn new(t: T) -> Self { + Mutex(parking_lot::Mutex::new(t)) + } + pub fn lock(&self) -> MutexGuard { + MutexGuard(self.0.lock()) + } +} + +impl<'g,T> Deref for MutexGuard<'g,T> { + type Target = T; + fn deref(&self) -> &T { &*self.0 } +} +impl<'g,T> DerefMut for MutexGuard<'g,T> { + fn deref_mut(&mut self) -> &mut T { &mut *self.0 } +} diff --git a/src/lib.rs b/src/lib.rs index 232001c0..8b206254 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,7 @@ pub mod clock; pub mod commands; pub mod config; pub mod deck; +pub mod debugmutex; pub mod debugreader; pub mod error; pub mod gamestate;