From 096afea6f13692fddbfad0b07e5377cb2e81dd58 Mon Sep 17 00:00:00 2001 From: Mica White Date: Thu, 26 Dec 2024 11:06:23 -0500 Subject: Rename kill to poison --- src/collection/boxed.rs | 6 ++++-- src/collection/owned.rs | 4 ++-- src/collection/ref.rs | 4 ++-- src/collection/retry.rs | 4 ++-- src/collection/utils.rs | 4 ++-- src/lockable.rs | 2 +- src/mutex/mutex.rs | 8 ++++---- src/poisonable/poisonable.rs | 4 ++-- src/rwlock/rwlock.rs | 14 +++++++------- 9 files changed, 26 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/collection/boxed.rs b/src/collection/boxed.rs index 2397bd3..a048d2b 100644 --- a/src/collection/boxed.rs +++ b/src/collection/boxed.rs @@ -21,9 +21,9 @@ fn contains_duplicates(l: &[&dyn RawLock]) -> bool { } unsafe impl RawLock for BoxedLockCollection { - fn kill(&self) { + fn poison(&self) { for lock in &self.locks { - lock.kill(); + lock.poison(); } } @@ -196,6 +196,8 @@ impl BoxedLockCollection { self.locks.clear(); // safety: this was allocated using a box, and is now unique let boxed: Box> = Box::from_raw(self.data.cast_mut()); + // to prevent a double free + std::mem::forget(self); boxed.into_inner() } diff --git a/src/collection/owned.rs b/src/collection/owned.rs index e4cfe46..59e1ff8 100644 --- a/src/collection/owned.rs +++ b/src/collection/owned.rs @@ -14,10 +14,10 @@ fn get_locks(data: &L) -> Vec<&dyn RawLock> { } unsafe impl RawLock for OwnedLockCollection { - fn kill(&self) { + fn poison(&self) { let locks = get_locks(&self.data); for lock in locks { - lock.kill(); + lock.poison(); } } diff --git a/src/collection/ref.rs b/src/collection/ref.rs index 4fa5485..a9c3579 100644 --- a/src/collection/ref.rs +++ b/src/collection/ref.rs @@ -40,9 +40,9 @@ where } unsafe impl RawLock for RefLockCollection<'_, L> { - fn kill(&self) { + fn poison(&self) { for lock in &self.locks { - lock.kill(); + lock.poison(); } } diff --git a/src/collection/retry.rs b/src/collection/retry.rs index 687c5ec..cb6a1fb 100644 --- a/src/collection/retry.rs +++ b/src/collection/retry.rs @@ -36,10 +36,10 @@ fn contains_duplicates(data: L) -> bool { } unsafe impl RawLock for RetryingLockCollection { - fn kill(&self) { + fn poison(&self) { let locks = get_locks(&self.data); for lock in locks { - lock.kill(); + lock.poison(); } } diff --git a/src/collection/utils.rs b/src/collection/utils.rs index f418386..36b19be 100644 --- a/src/collection/utils.rs +++ b/src/collection/utils.rs @@ -96,7 +96,7 @@ pub unsafe fn attempt_to_recover_locks_from_panic(locked: &RefCell RawLock for Mutex { - fn kill(&self) { + fn poison(&self) { self.poison.poison(); } @@ -22,7 +22,7 @@ unsafe impl RawLock for Mutex { // if the closure unwraps, then the mutex will be killed let this = AssertUnwindSafe(self); - handle_unwind(|| this.raw.lock(), || self.kill()) + handle_unwind(|| this.raw.lock(), || self.poison()) } unsafe fn raw_try_lock(&self) -> bool { @@ -32,13 +32,13 @@ unsafe impl RawLock for Mutex { // if the closure unwraps, then the mutex will be killed let this = AssertUnwindSafe(self); - handle_unwind(|| this.raw.try_lock(), || self.kill()) + handle_unwind(|| this.raw.try_lock(), || self.poison()) } unsafe fn raw_unlock(&self) { // if the closure unwraps, then the mutex will be killed let this = AssertUnwindSafe(self); - handle_unwind(|| this.raw.unlock(), || self.kill()) + handle_unwind(|| this.raw.unlock(), || self.poison()) } // this is the closest thing to a read we can get, but Sharable isn't diff --git a/src/poisonable/poisonable.rs b/src/poisonable/poisonable.rs index 79f90d9..3ef1cdd 100644 --- a/src/poisonable/poisonable.rs +++ b/src/poisonable/poisonable.rs @@ -12,8 +12,8 @@ use super::{ }; unsafe impl RawLock for Poisonable { - fn kill(&self) { - self.inner.kill() + fn poison(&self) { + self.inner.poison() } unsafe fn raw_lock(&self) { diff --git a/src/rwlock/rwlock.rs b/src/rwlock/rwlock.rs index 66c7362..8bb170c 100644 --- a/src/rwlock/rwlock.rs +++ b/src/rwlock/rwlock.rs @@ -14,7 +14,7 @@ use crate::lockable::{ use super::{PoisonFlag, RwLock, RwLockReadGuard, RwLockReadRef, RwLockWriteGuard, RwLockWriteRef}; unsafe impl RawLock for RwLock { - fn kill(&self) { + fn poison(&self) { self.poison.poison(); } @@ -26,7 +26,7 @@ unsafe impl RawLock for RwLock { // if the closure unwraps, then the mutex will be killed let this = AssertUnwindSafe(self); - handle_unwind(|| this.raw.lock_exclusive(), || self.kill()) + handle_unwind(|| this.raw.lock_exclusive(), || self.poison()) } unsafe fn raw_try_lock(&self) -> bool { @@ -36,13 +36,13 @@ unsafe impl RawLock for RwLock { // if the closure unwraps, then the mutex will be killed let this = AssertUnwindSafe(self); - handle_unwind(|| this.raw.try_lock_exclusive(), || self.kill()) + handle_unwind(|| this.raw.try_lock_exclusive(), || self.poison()) } unsafe fn raw_unlock(&self) { // if the closure unwraps, then the mutex will be killed let this = AssertUnwindSafe(self); - handle_unwind(|| this.raw.unlock_exclusive(), || self.kill()) + handle_unwind(|| this.raw.unlock_exclusive(), || self.poison()) } unsafe fn raw_read(&self) { @@ -53,7 +53,7 @@ unsafe impl RawLock for RwLock { // if the closure unwraps, then the mutex will be killed let this = AssertUnwindSafe(self); - handle_unwind(|| this.raw.lock_shared(), || self.kill()) + handle_unwind(|| this.raw.lock_shared(), || self.poison()) } unsafe fn raw_try_read(&self) -> bool { @@ -63,13 +63,13 @@ unsafe impl RawLock for RwLock { // if the closure unwraps, then the mutex will be killed let this = AssertUnwindSafe(self); - handle_unwind(|| this.raw.try_lock_shared(), || self.kill()) + handle_unwind(|| this.raw.try_lock_shared(), || self.poison()) } unsafe fn raw_unlock_read(&self) { // if the closure unwraps, then the mutex will be killed let this = AssertUnwindSafe(self); - handle_unwind(|| this.raw.unlock_shared(), || self.kill()) + handle_unwind(|| this.raw.unlock_shared(), || self.poison()) } } -- cgit v1.2.3