summaryrefslogtreecommitdiff
path: root/src/poisonable
diff options
context:
space:
mode:
Diffstat (limited to 'src/poisonable')
-rwxr-xr-xsrc/poisonable/poisonable.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/poisonable/poisonable.rs b/src/poisonable/poisonable.rs
index dd12cea..0134ff1 100755
--- a/src/poisonable/poisonable.rs
+++ b/src/poisonable/poisonable.rs
@@ -1,10 +1,11 @@
use std::panic::{RefUnwindSafe, UnwindSafe};
+use crate::collection::OwnedLockCollection;
use crate::handle_unwind::handle_unwind;
use crate::lockable::{
Lockable, LockableGetMut, LockableIntoInner, OwnedLockable, RawLock, Sharable,
};
-use crate::{Keyable, ThreadKey};
+use crate::{Keyable, LockContext, ThreadKey};
use super::{
PoisonError, PoisonFlag, PoisonGuard, PoisonRef, PoisonResult, Poisonable,
@@ -853,5 +854,24 @@ impl<L: LockableGetMut + RawLock> Poisonable<L> {
}
}
+impl<L: OwnedLockable> Poisonable<OwnedLockCollection<L>> {
+ /// Creates a context that can be used to iterate over the items in order.
+ ///
+ /// For more information, see [`OwnedLockCollection::context`].
+ ///
+ /// # Errors
+ ///
+ /// If another user of this lock panicked while holding the lock, then
+ /// this call will return an error instead. A `Poisonable` is poisoned
+ /// whenever a thread panics while holding a lock.
+ pub fn context(&self) -> PoisonResult<LockContext<'_, L>> {
+ if self.is_poisoned() {
+ Ok(self.inner.context())
+ } else {
+ Err(PoisonError::new(self.inner.context()))
+ }
+ }
+}
+
impl<L: UnwindSafe> RefUnwindSafe for Poisonable<L> {}
impl<L: UnwindSafe> UnwindSafe for Poisonable<L> {}