summaryrefslogtreecommitdiffstats
path: root/vendor/fd-lock/src/write_guard.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/fd-lock/src/write_guard.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/fd-lock/src/write_guard.rs')
-rw-r--r--vendor/fd-lock/src/write_guard.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/vendor/fd-lock/src/write_guard.rs b/vendor/fd-lock/src/write_guard.rs
new file mode 100644
index 000000000..e218e3842
--- /dev/null
+++ b/vendor/fd-lock/src/write_guard.rs
@@ -0,0 +1,50 @@
+use std::ops;
+
+use crate::sys;
+
+/// RAII structure used to release the exclusive write access of a lock when
+/// dropped.
+///
+/// This structure is created by the [`write`] and [`try_write`] methods
+/// on [`RwLock`].
+///
+/// [`write`]: crate::RwLock::write
+/// [`try_write`]: crate::RwLock::try_write
+/// [`RwLock`]: crate::RwLock
+///
+/// # Panics
+///
+/// Dropping this type may panic if the lock fails to unlock.
+#[must_use = "if unused the RwLock will immediately unlock"]
+#[derive(Debug)]
+pub struct RwLockWriteGuard<'lock, T: sys::AsRaw> {
+ guard: sys::RwLockWriteGuard<'lock, T>,
+}
+
+impl<'lock, T: sys::AsRaw> RwLockWriteGuard<'lock, T> {
+ pub(crate) fn new(guard: sys::RwLockWriteGuard<'lock, T>) -> Self {
+ Self { guard }
+ }
+}
+
+impl<T: sys::AsRaw> ops::Deref for RwLockWriteGuard<'_, T> {
+ type Target = T;
+
+ #[inline]
+ fn deref(&self) -> &Self::Target {
+ self.guard.deref()
+ }
+}
+
+impl<T: sys::AsRaw> ops::DerefMut for RwLockWriteGuard<'_, T> {
+ #[inline]
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ self.guard.deref_mut()
+ }
+}
+
+/// Release the lock.
+impl<T: sys::AsRaw> Drop for RwLockWriteGuard<'_, T> {
+ #[inline]
+ fn drop(&mut self) {}
+}