Skip to content

Commit

Permalink
Use more precise unsafe scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
cynecx committed Feb 11, 2020
1 parent 8abcc14 commit 8903df8
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions crossbeam-epoch/src/sync/queue.rs
Expand Up @@ -142,24 +142,22 @@ impl<T> Queue<T> {
let head = self.head.load(Acquire, guard);
let h = unsafe { head.deref() };
let next = h.next.load(Acquire, guard);
unsafe {
match next.as_ref() {
Some(n) if condition(&*n.data.as_ptr()) => {
self.head
.compare_and_set(head, next, Release, guard)
.map(|_| {
let tail = self.tail.load(Relaxed, guard);
// Advance the tail so that we don't retire a pointer to a reachable node.
if head == tail {
let _ = self.tail.compare_and_set(tail, next, Release, guard);
}
guard.defer_destroy(head);
Some(n.data.as_ptr().read())
})
.map_err(|_| ())
}
None | Some(_) => Ok(None),
}
match unsafe { next.as_ref() } {
Some(n) if condition(unsafe { &*n.data.as_ptr() }) => unsafe {
self.head
.compare_and_set(head, next, Release, guard)
.map(|_| {
let tail = self.tail.load(Relaxed, guard);
// Advance the tail so that we don't retire a pointer to a reachable node.
if head == tail {
let _ = self.tail.compare_and_set(tail, next, Release, guard);
}
guard.defer_destroy(head);
Some(n.data.as_ptr().read())
})
.map_err(|_| ())
},
None | Some(_) => Ok(None),
}
}

Expand Down

0 comments on commit 8903df8

Please sign in to comment.