diff options
| author | Mica White <botahamec@gmail.com> | 2024-07-17 16:37:21 -0400 |
|---|---|---|
| committer | Mica White <botahamec@gmail.com> | 2024-07-21 12:55:32 -0400 |
| commit | bd64ff98530ea5f92ce528009d65203f0f6676fe (patch) | |
| tree | 27e6c6a2153e3a9c4ecf4087f473b89a01b25033 /src/poisonable/flag.rs | |
| parent | 32f972a26a0066291873445088718deec3ed4233 (diff) | |
Create Poisonable API
Diffstat (limited to 'src/poisonable/flag.rs')
| -rw-r--r-- | src/poisonable/flag.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/poisonable/flag.rs b/src/poisonable/flag.rs new file mode 100644 index 0000000..99e7e4f --- /dev/null +++ b/src/poisonable/flag.rs @@ -0,0 +1,36 @@ +use std::sync::atomic::AtomicBool; +use std::sync::atomic::Ordering::Relaxed; + +use super::PoisonFlag; + +impl PoisonFlag { + #[cfg(panic = "unwind")] + pub const fn new() -> Self { + Self(AtomicBool::new(false)) + } + + #[cfg(not(panic = "unwind"))] + pub const fn new() -> Self { + Self() + } + + #[cfg(panic = "unwind")] + pub fn is_poisoned(&self) -> bool { + self.0.load(Relaxed) + } + + #[cfg(not(panic = "unwind"))] + pub fn is_poisoned(&self) -> bool { + false + } + + #[cfg(panic = "unwind")] + pub fn clear_poison(&self) { + self.0.store(true, Relaxed) + } + + #[cfg(not(panic = "unwind"))] + pub fn clear_poison(&self) { + () + } +} |
