diff --git a/src/lib.rs b/src/lib.rs index ac0188b..2e0b1e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,35 +91,6 @@ where } } - /// Take the current content, write it into P then do a CAS to extent this - /// Atom with the previous contents. This can be used to create a LIFO - /// - /// Returns true if this set this migrated the Atom from null. - pub fn replace_and_set_next( - &self, - mut value: P, - load_order: Ordering, - cas_order: Ordering, - ) -> bool - where - P: GetNextMut>, - { - let next = value.get_next() as *mut Option

; - let raw = value.into_raw(); - // If next was set to Some(P) we want to - // assert that it was droppeds - unsafe { ptr::drop_in_place(next) }; - loop { - let pcurrent = self.inner.load(load_order); - let current = unsafe { Self::inner_from_raw(pcurrent) }; - unsafe { ptr::write(next, current) }; - let last = self.inner.compare_and_swap(pcurrent, raw, cas_order); - if last == pcurrent { - return last.is_null(); - } - } - } - /// Check to see if an atom is None /// /// This only means that the contents was None when it was measured @@ -430,10 +401,3 @@ where }) } } - -/// This is a utility Trait that fetches the next ptr from -/// an object. -pub trait GetNextMut { - type NextPtr; - fn get_next(&mut self) -> &mut Self::NextPtr; -} diff --git a/tests/atom.rs b/tests/atom.rs index 17f7e08..24630b3 100644 --- a/tests/atom.rs +++ b/tests/atom.rs @@ -230,82 +230,6 @@ fn get_arc() { assert_eq!(v.load(Ordering::SeqCst), 1); } -#[derive(Debug)] -struct Link { - next: Option>, - value: u32, -} - -impl Link { - fn new(v: u32) -> Box { - Box::new(Link { - next: None, - value: v, - }) - } -} - -impl GetNextMut for Box { - type NextPtr = Option>; - fn get_next(&mut self) -> &mut Option> { - &mut self.next - } -} - -#[test] -fn lifo() { - let atom = Atom::empty(); - for i in 0..100 { - let x = atom.replace_and_set_next(Link::new(99 - i), Ordering::Relaxed, Ordering::AcqRel); - assert_eq!(x, i == 0); - } - - let expected: Vec = (0..100).collect(); - let mut found = Vec::new(); - let mut chain = atom.take(Ordering::Acquire); - while let Some(v) = chain { - found.push(v.value); - chain = v.next; - } - assert_eq!(expected, found); -} - -#[allow(dead_code)] -struct LinkCanary { - next: Option>, - value: Canary, -} - -impl LinkCanary { - fn new(v: Canary) -> Box { - Box::new(LinkCanary { - next: None, - value: v, - }) - } -} - -impl GetNextMut for Box { - type NextPtr = Option>; - fn get_next(&mut self) -> &mut Option> { - &mut self.next - } -} - -#[test] -fn lifo_drop() { - let v = Arc::new(AtomicUsize::new(0)); - let canary = Canary(v.clone()); - let mut link = LinkCanary::new(canary.clone()); - link.next = Some(LinkCanary::new(canary.clone())); - - let atom = Atom::empty(); - atom.replace_and_set_next(link, Ordering::Relaxed, Ordering::AcqRel); - assert_eq!(1, v.load(Ordering::SeqCst)); - drop(atom); - assert_eq!(2, v.load(Ordering::SeqCst)); -} - #[test] fn borrow() { let a = Atom::new(&5);