568 |
|
} |
569 |
|
|
570 |
|
/** |
571 |
< |
* Collapse dead (matched) nodes between pred and q. |
571 |
> |
* Collapses dead (matched) nodes between pred and q. |
572 |
|
* @param pred the last known live node, or null if none |
573 |
|
* @param c the first dead node |
574 |
|
* @param p the last dead node |
590 |
|
? pred : p; |
591 |
|
} |
592 |
|
|
593 |
+ |
/** |
594 |
+ |
* Collapses dead (matched) nodes between h and p. |
595 |
+ |
* h was once head, and all nodes between h and p are dead. |
596 |
+ |
*/ |
597 |
+ |
private void skipDeadNodesNearHead(Node h, Node p) { |
598 |
+ |
// assert h != p; |
599 |
+ |
// assert p.isMatched(); |
600 |
+ |
// find live or trailing node, starting at p |
601 |
+ |
for (Node q; (q = p.next) != null; ) { |
602 |
+ |
if (!q.isMatched()) { |
603 |
+ |
p = q; |
604 |
+ |
break; |
605 |
+ |
} |
606 |
+ |
if (p == (p = q)) |
607 |
+ |
return; |
608 |
+ |
} |
609 |
+ |
if (h == HEAD.getAcquire(this) && casHead(h, p)) |
610 |
+ |
h.selfLink(); |
611 |
+ |
} |
612 |
+ |
|
613 |
|
/* Possible values for "how" argument in xfer method. */ |
614 |
|
|
615 |
|
private static final int NOW = 0; // for untimed poll, tryTransfer |
642 |
|
break; |
643 |
|
if (p.tryMatch(item, e)) { |
644 |
|
// collapse at least 2 |
645 |
< |
if (h != p) tryCollapseHead: { |
626 |
< |
// find live or trailing node |
627 |
< |
for (Node q; (q = p.next) != null; ) { |
628 |
< |
if (!q.isMatched()) { |
629 |
< |
p = q; |
630 |
< |
break; |
631 |
< |
} |
632 |
< |
if (p == (p = q)) |
633 |
< |
break tryCollapseHead; |
634 |
< |
} |
635 |
< |
if (h == head && casHead(h, p)) |
636 |
< |
h.selfLink(); |
637 |
< |
} |
645 |
> |
if (h != p) skipDeadNodesNearHead(h, p); |
646 |
|
@SuppressWarnings("unchecked") E itemE = (E) item; |
647 |
|
return itemE; |
648 |
|
} |
676 |
|
private Node tryAppend(Node s, boolean haveData) { |
677 |
|
// assert head != null; |
678 |
|
// assert tail != null; |
679 |
+ |
// assert s.isData == haveData; |
680 |
|
for (Node t = tail, p = t;;) { // move p to last node and append |
681 |
|
Node n, u; // temps for reads of next & tail |
682 |
|
if (p == null) |