summaryrefslogtreecommitdiff
path: root/src/rwlock
diff options
context:
space:
mode:
authorMica White <botahamec@gmail.com>2024-12-23 12:54:01 -0500
committerMica White <botahamec@gmail.com>2024-12-23 12:54:01 -0500
commitcbdce939291800f297acc700e02db8b6798239ce (patch)
treede3b407c3a93707937797194106419ba6b0eb23b /src/rwlock
parentb2281e6aec631dc7c6d69edef9268ce7e00ed1dc (diff)
Utilize mutex death
Diffstat (limited to 'src/rwlock')
-rw-r--r--src/rwlock/rwlock.rs72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/rwlock/rwlock.rs b/src/rwlock/rwlock.rs
index 86005e3..94c6062 100644
--- a/src/rwlock/rwlock.rs
+++ b/src/rwlock/rwlock.rs
@@ -21,6 +21,18 @@ unsafe impl<T: ?Sized, R: RawRwLock> RawLock for RwLock<T, R> {
"The read-write lock has been killed"
);
+ scopeguard::defer_on_unwind! {
+ scopeguard::defer_on_unwind! { self.kill() };
+ if self.raw_try_lock() {
+ self.raw_unlock();
+ } else {
+ // We don't know whether this lock is locked by the current
+ // thread, or another thread. There's not much we can do other
+ // than kill it.
+ self.kill();
+ }
+ }
+
self.raw.lock_exclusive()
}
@@ -29,10 +41,34 @@ unsafe impl<T: ?Sized, R: RawRwLock> RawLock for RwLock<T, R> {
return false;
}
+ scopeguard::defer_on_unwind! {
+ scopeguard::defer_on_unwind! { self.kill() };
+ if self.raw_try_lock() {
+ self.raw_unlock();
+ } else {
+ // We don't know whether this lock is locked by the current
+ // thread, or another thread. There's not much we can do other
+ // than kill it.
+ self.kill();
+ }
+ }
+
self.raw.try_lock_exclusive()
}
unsafe fn raw_unlock(&self) {
+ scopeguard::defer_on_unwind! {
+ scopeguard::defer_on_unwind! { self.kill() };
+ if self.raw_try_lock() {
+ self.raw_unlock();
+ } else {
+ // We don't know whether this lock is locked by the current
+ // thread, or another thread. There's not much we can do other
+ // than kill it.
+ self.kill();
+ }
+ }
+
self.raw.unlock_exclusive()
}
@@ -42,6 +78,18 @@ unsafe impl<T: ?Sized, R: RawRwLock> RawLock for RwLock<T, R> {
"The read-write lock has been killed"
);
+ scopeguard::defer_on_unwind! {
+ scopeguard::defer_on_unwind! { self.kill() };
+ if self.raw_try_read() {
+ self.raw_unlock_read();
+ } else {
+ // We don't know whether this lock is locked by the current
+ // thread, or another thread. There's not much we can do other
+ // than kill it.
+ self.kill();
+ }
+ }
+
self.raw.lock_shared()
}
@@ -50,10 +98,34 @@ unsafe impl<T: ?Sized, R: RawRwLock> RawLock for RwLock<T, R> {
return false;
}
+ scopeguard::defer_on_unwind! {
+ scopeguard::defer_on_unwind! { self.kill() };
+ if self.raw_try_read() {
+ self.raw_unlock_read();
+ } else {
+ // We don't know whether this lock is locked by the current
+ // thread, or another thread. There's not much we can do other
+ // than kill it.
+ self.kill();
+ }
+ }
+
self.raw.try_lock_shared()
}
unsafe fn raw_unlock_read(&self) {
+ scopeguard::defer_on_unwind! {
+ scopeguard::defer_on_unwind! { self.kill() };
+ if self.raw_try_read() {
+ self.raw_unlock_read();
+ } else {
+ // We don't know whether this lock is locked by the current
+ // thread, or another thread. There's not much we can do other
+ // than kill it.
+ self.kill();
+ }
+ }
+
self.raw.unlock_shared()
}
}