mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8189387: ConcurrentLinkedDeque linearizability continued ..
Reviewed-by: martin, psandoz, dholmes
This commit is contained in:
parent
42ad4ec2dd
commit
e2cbace23d
2 changed files with 80 additions and 44 deletions
|
@ -695,8 +695,9 @@ public class ConcurrentLinkedDeque<E>
|
|||
* stale pointer that is now off the list.
|
||||
*/
|
||||
final Node<E> pred(Node<E> p) {
|
||||
Node<E> q = p.prev;
|
||||
return (p == q) ? last() : q;
|
||||
if (p == (p = p.prev))
|
||||
p = last();
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -867,31 +868,31 @@ public class ConcurrentLinkedDeque<E>
|
|||
|
||||
public E peekFirst() {
|
||||
restart: for (;;) {
|
||||
for (Node<E> first = first(), p = first;;) {
|
||||
final E item;
|
||||
if ((item = p.item) != null) {
|
||||
// recheck for linearizability
|
||||
if (first.prev != null) continue restart;
|
||||
return item;
|
||||
}
|
||||
if ((p = succ(p)) == null)
|
||||
return null;
|
||||
E item;
|
||||
Node<E> first = first(), p = first;
|
||||
while ((item = p.item) == null) {
|
||||
if (p == (p = p.next)) continue restart;
|
||||
if (p == null)
|
||||
break;
|
||||
}
|
||||
// recheck for linearizability
|
||||
if (first.prev != null) continue restart;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
public E peekLast() {
|
||||
restart: for (;;) {
|
||||
for (Node<E> last = last(), p = last;;) {
|
||||
final E item;
|
||||
if ((item = p.item) != null) {
|
||||
// recheck for linearizability
|
||||
if (last.next != null) continue restart;
|
||||
return item;
|
||||
}
|
||||
if ((p = pred(p)) == null)
|
||||
return null;
|
||||
E item;
|
||||
Node<E> last = last(), p = last;
|
||||
while ((item = p.item) == null) {
|
||||
if (p == (p = p.prev)) continue restart;
|
||||
if (p == null)
|
||||
break;
|
||||
}
|
||||
// recheck for linearizability
|
||||
if (last.next != null) continue restart;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -921,8 +922,11 @@ public class ConcurrentLinkedDeque<E>
|
|||
return item;
|
||||
}
|
||||
}
|
||||
if ((p = succ(p)) == null)
|
||||
if (p == (p = p.next)) continue restart;
|
||||
if (p == null) {
|
||||
if (first.prev != null) continue restart;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -939,8 +943,11 @@ public class ConcurrentLinkedDeque<E>
|
|||
return item;
|
||||
}
|
||||
}
|
||||
if ((p = pred(p)) == null)
|
||||
if (p == (p = p.prev)) continue restart;
|
||||
if (p == null) {
|
||||
if (last.next != null) continue restart;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue