Skip to content

Commit

Permalink
Reduce amount of code in unsafe blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
dbkaplun committed May 11, 2018
1 parent 7f29a87 commit 24c15e5
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,18 @@ where
where
P: GetNextMut<NextPtr = Option<P>>,
{
unsafe {
let next = value.get_next() as *mut Option<P>;
let raw = value.into_raw();
// Iff next was set to Some(P) we want to
// assert that it was droppeds
drop(ptr::read(next));
loop {
let pcurrent = self.inner.load(load_order);
let current = Self::inner_from_raw(pcurrent);
ptr::write(next, current);
let last = self.inner.compare_and_swap(pcurrent, raw, cas_order);
if last == pcurrent {
return last.is_null();
}
let next = value.get_next() as *mut Option<P>;
let raw = value.into_raw();
// Iff next was set to Some(P) we want to
// assert that it was droppeds
drop(unsafe { ptr::read(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();
}
}
}
Expand Down

0 comments on commit 24c15e5

Please sign in to comment.