18 |
|
import java.util.concurrent.atomic.AtomicReference; |
19 |
|
|
20 |
|
/** |
21 |
< |
* An unbounded {@linkplain TransferQueue} based on linked nodes. |
21 |
> |
* An unbounded {@link TransferQueue} based on linked nodes. |
22 |
|
* This queue orders elements FIFO (first-in-first-out) with respect |
23 |
|
* to any given producer. The <em>head</em> of the queue is that |
24 |
|
* element that has been on the queue the longest time for some |
294 |
|
* @param e the comparison value for checking match |
295 |
|
* @param mode mode |
296 |
|
* @param nanos timeout value |
297 |
< |
* @return matched item, or s if cancelled |
297 |
> |
* @return matched item, or null if cancelled |
298 |
|
*/ |
299 |
|
private E awaitFulfill(Node<E> pred, Node<E> s, E e, |
300 |
|
int mode, long nanos) { |
360 |
|
for (;;) { |
361 |
|
Node<E> h = head.get(); |
362 |
|
Node<E> first = h.next; |
363 |
< |
if (first != null && first.next == first) { // help advance |
363 |
> |
if (first != null && first.get() == first) { // help advance |
364 |
|
advanceHead(h, first); |
365 |
|
continue; |
366 |
|
} |
522 |
|
} |
523 |
|
|
524 |
|
/** |
525 |
< |
* Transfers the specified element immediately if there exists a |
526 |
< |
* consumer already waiting to receive it (in {@link #take} or |
527 |
< |
* timed {@link #poll(long,TimeUnit) poll}), otherwise |
528 |
< |
* returning {@code false} without enqueuing the element. |
525 |
> |
* Transfers the element to a waiting consumer immediately, if possible. |
526 |
> |
* |
527 |
> |
* <p>More precisely, transfers the specified element immediately |
528 |
> |
* if there exists a consumer already waiting to receive it (in |
529 |
> |
* {@link #take} or timed {@link #poll(long,TimeUnit) poll}), |
530 |
> |
* otherwise returning {@code false} without enqueuing the element. |
531 |
|
* |
532 |
|
* @throws NullPointerException if the specified element is null |
533 |
|
*/ |
537 |
|
} |
538 |
|
|
539 |
|
/** |
540 |
< |
* Inserts the specified element at the tail of this queue, |
541 |
< |
* waiting if necessary for the element to be received by a |
542 |
< |
* consumer invoking {@code take} or {@code poll}. |
540 |
> |
* Transfers the element to a consumer, waiting if necessary to do so. |
541 |
> |
* |
542 |
> |
* <p>More precisely, transfers the specified element immediately |
543 |
> |
* if there exists a consumer already waiting to receive it (in |
544 |
> |
* {@link #take} or timed {@link #poll(long,TimeUnit) poll}), |
545 |
> |
* else inserts the specified element at the tail of this queue |
546 |
> |
* and waits until the element is received by a consumer. |
547 |
|
* |
548 |
|
* @throws NullPointerException if the specified element is null |
549 |
|
*/ |
556 |
|
} |
557 |
|
|
558 |
|
/** |
559 |
< |
* Inserts the specified element at the tail of this queue, |
560 |
< |
* waiting up to the specified wait time for the element to be |
561 |
< |
* received by a consumer invoking {@code take} or {@code poll}. |
559 |
> |
* Transfers the element to a consumer if it is possible to do so |
560 |
> |
* before the timeout elapses. |
561 |
> |
* |
562 |
> |
* <p>More precisely, transfers the specified element immediately |
563 |
> |
* if there exists a consumer already waiting to receive it (in |
564 |
> |
* {@link #take} or timed {@link #poll(long,TimeUnit) poll}), |
565 |
> |
* else inserts the specified element at the tail of this queue |
566 |
> |
* and waits until the element is received by a consumer, |
567 |
> |
* returning {@code false} if the specified wait time elapses |
568 |
> |
* before the element can be transferred. |
569 |
|
* |
570 |
|
* @throws NullPointerException if the specified element is null |
571 |
|
*/ |
762 |
|
} |
763 |
|
} |
764 |
|
|
765 |
+ |
/** |
766 |
+ |
* Returns {@code true} if this queue contains no elements. |
767 |
+ |
* |
768 |
+ |
* @return {@code true} if this queue contains no elements |
769 |
+ |
*/ |
770 |
|
public boolean isEmpty() { |
771 |
|
for (;;) { |
772 |
|
Node<E> h = traversalHead(); |
848 |
|
} |
849 |
|
} |
850 |
|
|
851 |
+ |
/** |
852 |
+ |
* Removes a single instance of the specified element from this queue, |
853 |
+ |
* if it is present. More formally, removes an element {@code e} such |
854 |
+ |
* that {@code o.equals(e)}, if this queue contains one or more such |
855 |
+ |
* elements. |
856 |
+ |
* Returns {@code true} if this queue contained the specified element |
857 |
+ |
* (or equivalently, if this queue changed as a result of the call). |
858 |
+ |
* |
859 |
+ |
* @param o element to be removed from this queue, if present |
860 |
+ |
* @return {@code true} if this queue changed as a result of the call |
861 |
+ |
*/ |
862 |
|
public boolean remove(Object o) { |
863 |
|
if (o == null) |
864 |
|
return false; |