15 |
|
import java.util.NoSuchElementException; |
16 |
|
import java.util.Queue; |
17 |
|
import java.util.concurrent.locks.LockSupport; |
18 |
+ |
|
19 |
|
/** |
20 |
|
* An unbounded {@link TransferQueue} based on linked nodes. |
21 |
|
* This queue orders elements FIFO (first-in-first-out) with respect |
423 |
|
} |
424 |
|
|
425 |
|
final boolean casItem(Object cmp, Object val) { |
426 |
< |
assert cmp == null || cmp.getClass() != Node.class; |
426 |
> |
// assert cmp == null || cmp.getClass() != Node.class; |
427 |
|
return UNSAFE.compareAndSwapObject(this, itemOffset, cmp, val); |
428 |
|
} |
429 |
|
|
447 |
|
/** |
448 |
|
* Sets item to self and waiter to null, to avoid garbage |
449 |
|
* retention after matching or cancelling. Uses relaxed writes |
450 |
< |
* bacause order is already constrained in the only calling |
450 |
> |
* because order is already constrained in the only calling |
451 |
|
* contexts: item is forgotten only after volatile/atomic |
452 |
|
* mechanics that extract items. Similarly, clearing waiter |
453 |
|
* follows either CAS or return from park (if ever parked; |
489 |
|
* Tries to artificially match a data node -- used by remove. |
490 |
|
*/ |
491 |
|
final boolean tryMatchData() { |
492 |
< |
assert isData; |
492 |
> |
// assert isData; |
493 |
|
Object x = item; |
494 |
|
if (x != null && x != this && casItem(x, null)) { |
495 |
|
LockSupport.unpark(waiter); |
542 |
|
|
543 |
|
@SuppressWarnings("unchecked") |
544 |
|
static <E> E cast(Object item) { |
545 |
< |
assert item == null || item.getClass() != Node.class; |
545 |
> |
// assert item == null || item.getClass() != Node.class; |
546 |
|
return (E) item; |
547 |
|
} |
548 |
|
|
657 |
|
for (;;) { |
658 |
|
Object item = s.item; |
659 |
|
if (item != e) { // matched |
660 |
< |
assert item != s; |
660 |
> |
// assert item != s; |
661 |
|
s.forgetContents(); // avoid garbage |
662 |
|
return this.<E>cast(item); |
663 |
|
} |
1126 |
|
* @return {@code true} if this queue contains no elements |
1127 |
|
*/ |
1128 |
|
public boolean isEmpty() { |
1129 |
< |
return firstOfMode(true) == null; |
1129 |
> |
for (Node p = head; p != null; p = succ(p)) { |
1130 |
> |
if (!p.isMatched()) |
1131 |
> |
return !p.isData; |
1132 |
> |
} |
1133 |
> |
return true; |
1134 |
|
} |
1135 |
|
|
1136 |
|
public boolean hasWaitingConsumer() { |