diff options
| author | Botahamec <botahamec@outlook.com> | 2024-05-23 19:50:32 -0400 |
|---|---|---|
| committer | Botahamec <botahamec@outlook.com> | 2024-05-23 19:50:32 -0400 |
| commit | f81d4b40a007fecf6502a36b4c24a1e31807a731 (patch) | |
| tree | b4cc65f0ccbc118e47ede4e6556fa1123aae41c8 /src/collection/owned.rs | |
| parent | fa39064fe2f3399d27762a23c54d4703d00bd199 (diff) | |
Comments
Diffstat (limited to 'src/collection/owned.rs')
| -rw-r--r-- | src/collection/owned.rs | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/src/collection/owned.rs b/src/collection/owned.rs index e1549b2..919c403 100644 --- a/src/collection/owned.rs +++ b/src/collection/owned.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use crate::lockable::{Lockable, OwnedLockable, RawLock, Sharable}; use crate::Keyable; -use super::{LockGuard, OwnedLockCollection}; +use super::{utils, LockGuard, OwnedLockCollection}; fn get_locks<L: Lockable>(data: &L) -> Vec<&dyn RawLock> { let mut locks = Vec::new(); @@ -191,17 +191,8 @@ impl<L: OwnedLockable> OwnedLockCollection<L> { ) -> Option<LockGuard<'key, L::Guard<'g>, Key>> { let locks = get_locks(&self.data); let guard = unsafe { - for (i, lock) in locks.iter().enumerate() { - // safety: we have the thread key - let success = lock.try_lock(); - - if !success { - for lock in &locks[0..i] { - // safety: this lock was already acquired - lock.unlock(); - } - return None; - } + if !utils::ordered_try_lock(&locks) { + return None; } // safety: we've acquired the locks @@ -315,17 +306,8 @@ impl<L: Sharable> OwnedLockCollection<L> { ) -> Option<LockGuard<'key, L::ReadGuard<'g>, Key>> { let locks = get_locks(&self.data); let guard = unsafe { - for (i, lock) in locks.iter().enumerate() { - // safety: we have the thread key - let success = lock.try_read(); - - if !success { - for lock in &locks[0..i] { - // safety: this lock was already acquired - lock.unlock(); - } - return None; - } + if !utils::ordered_try_read(&locks) { + return None; } // safety: we've acquired the locks |
