From bd64ff98530ea5f92ce528009d65203f0f6676fe Mon Sep 17 00:00:00 2001 From: Mica White Date: Wed, 17 Jul 2024 16:37:21 -0400 Subject: Create Poisonable API --- src/poisonable.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/poisonable.rs (limited to 'src/poisonable.rs') 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 { + 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, +} + +pub enum TryLockPoisonableError<'flag, 'key, G, Key: 'key> { + Poisoned(PoisonError>), + WouldBlock(Key), +} + +pub type PoisonResult = Result>; + +pub type TryLockPoisonableResult<'flag, 'key, G, Key> = + Result, TryLockPoisonableError<'flag, 'key, G, Key>>; -- cgit v1.2.3