diff --git a/src/atomic_option.rs b/src/atomic_option.rs deleted file mode 100644 index 3b53629..0000000 --- a/src/atomic_option.rs +++ /dev/null @@ -1,55 +0,0 @@ -use std::sync::atomic::{AtomicPtr, Ordering}; -use std::ptr; - -unsafe impl Send for AtomicOption {} -unsafe impl Sync for AtomicOption {} - -#[derive(Debug)] -pub struct AtomicOption { - inner: AtomicPtr, -} - -impl Drop for AtomicOption { - fn drop(&mut self) { - let inner = self.inner.load(Ordering::Relaxed); - if !inner.is_null() { - unsafe { - drop(Box::from_raw(inner)); - } - } - } -} - -impl AtomicOption { - pub fn new() -> Self { - AtomicOption { inner: AtomicPtr::new(ptr::null_mut()) } - } - - fn swap_inner(&self, ptr: *mut T, order: Ordering) -> Option> { - let old = self.inner.swap(ptr, order); - if old.is_null() { - None - } else { - Some(unsafe { Box::from_raw(old) }) - } - } - - // allows re-use of allocation - pub fn swap_box(&self, t: Box, order: Ordering) -> Option> { - self.swap_inner(Box::into_raw(t), order) - } - - pub fn swap(&self, t: T, order: Ordering) -> Option { - self.swap_box(Box::new(t), order).map(|old| *old) - } - - pub fn take(&self, order: Ordering) -> Option { - self.swap_inner(ptr::null_mut(), order).map(|old| *old) - } -} - -impl Default for AtomicOption { - fn default() -> Self { - Self::new() - } -} diff --git a/src/lib.rs b/src/lib.rs index 1d5635c..fa0827b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,5 @@ extern crate cfg_if; pub mod cache_padded; #[cfg(feature = "use_std")] -pub mod atomic_option; -#[cfg(feature = "use_std")] pub mod scoped; pub mod consume;