6871697: LinkedBlockingQueue Iterator/remove/poll race
More checks for node.next == node Reviewed-by: martin, dholmes, chegar
This commit is contained in:
parent
50754f7c2e
commit
f1047d3739
@ -766,19 +766,21 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlike other traversal methods, iterators need to handle:
|
* Returns the next live successor of p, or null if no such.
|
||||||
|
*
|
||||||
|
* Unlike other traversal methods, iterators need to handle both:
|
||||||
* - dequeued nodes (p.next == p)
|
* - dequeued nodes (p.next == p)
|
||||||
* - interior removed nodes (p.item == null)
|
* - (possibly multiple) interior removed nodes (p.item == null)
|
||||||
*/
|
*/
|
||||||
private Node<E> nextNode(Node<E> p) {
|
private Node<E> nextNode(Node<E> p) {
|
||||||
Node<E> s = p.next;
|
for (;;) {
|
||||||
if (p == s)
|
Node<E> s = p.next;
|
||||||
return head.next;
|
if (s == p)
|
||||||
// Skip over removed nodes.
|
return head.next;
|
||||||
// May be necessary if multiple interior Nodes are removed.
|
if (s == null || s.item != null)
|
||||||
while (s != null && s.item == null)
|
return s;
|
||||||
s = s.next;
|
p = s;
|
||||||
return s;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public E next() {
|
public E next() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user