From 75e75ec706c8737ea960504fc32d6b6af0a9d503 Mon Sep 17 00:00:00 2001 From: Janis Date: Sun, 19 Jan 2025 18:42:45 +0100 Subject: [PATCH] util: rawmutexguard: MutexGuard for RawMutex --- crates/renderer/src/util.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/renderer/src/util.rs b/crates/renderer/src/util.rs index 1183bfc..08d9982 100644 --- a/crates/renderer/src/util.rs +++ b/crates/renderer/src/util.rs @@ -521,6 +521,29 @@ impl<'a> Iterator for ChunkedBitIter<'a> { } } +pub struct RawMutexGuard<'a, T> { + pub(crate) mutex: &'a parking_lot::RawMutex, + pub(crate) value: &'a T, + pub(crate) _pd: std::marker::PhantomData<&'a ()>, +} + +impl<'a, T> std::ops::Deref for RawMutexGuard<'a, T> { + type Target = T; + + fn deref(&self) -> &Self::Target { + self.value + } +} + +impl Drop for RawMutexGuard<'_, T> { + fn drop(&mut self) { + use parking_lot::lock_api::RawMutex; + unsafe { + self.mutex.unlock(); + } + } +} + pub struct CStringList { pub strings: Box<[*const i8]>, bytes: Box<[u8]>,