summaryrefslogtreecommitdiff
path: root/src/poisonable.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/poisonable.rs')
-rw-r--r--src/poisonable.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/poisonable.rs b/src/poisonable.rs
new file mode 100644
index 0000000..49979e5
--- /dev/null
+++ b/src/poisonable.rs
@@ -0,0 +1,46 @@
+#[cfg(not(panic = "unwind"))]
+use std::convert::Infallible;
+use std::marker::PhantomData;
+use std::sync::atomic::AtomicBool;
+
+use crate::lockable::{Lockable, RawLock};
+
+mod error;
+mod flag;
+mod guard;
+mod poisonable;
+
+#[derive(Debug, Default)]
+struct PoisonFlag(#[cfg(panic = "unwind")] AtomicBool);
+
+#[derive(Debug, Default)]
+pub struct Poisonable<L: Lockable + RawLock> {
+ inner: L,
+ poisoned: PoisonFlag,
+}
+
+pub struct PoisonRef<'flag, G> {
+ guard: G,
+ #[cfg(panic = "unwind")]
+ flag: &'flag PoisonFlag,
+}
+
+pub struct PoisonGuard<'flag, 'key, G, Key> {
+ guard: PoisonRef<'flag, G>,
+ key: Key,
+ _phantom: PhantomData<&'key ()>,
+}
+
+pub struct PoisonError<Guard> {
+ guard: Guard,
+}
+
+pub enum TryLockPoisonableError<'flag, 'key, G, Key: 'key> {
+ Poisoned(PoisonError<PoisonGuard<'flag, 'key, G, Key>>),
+ WouldBlock(Key),
+}
+
+pub type PoisonResult<Guard> = Result<Guard, PoisonError<Guard>>;
+
+pub type TryLockPoisonableResult<'flag, 'key, G, Key> =
+ Result<PoisonGuard<'flag, 'key, G, Key>, TryLockPoisonableError<'flag, 'key, G, Key>>;