30 |
|
* |
31 |
|
* <p>This class and its iterator implement all of the |
32 |
|
* <em>optional</em> methods of the {@link Collection} and {@link |
33 |
< |
* Iterator} interfaces. |
33 |
> |
* Iterator} interfaces. |
34 |
|
* |
35 |
|
* <p>This class is a member of the |
36 |
|
* <a href="{@docRoot}/../guide/collections/index.html"> |
57 |
|
* items have been entered since the signal. And symmetrically for |
58 |
|
* takes signalling puts. Operations such as remove(Object) and |
59 |
|
* iterators acquire both locks. |
60 |
< |
*/ |
60 |
> |
*/ |
61 |
|
|
62 |
|
/** |
63 |
|
* Linked list node class |
189 |
|
*/ |
190 |
|
public LinkedBlockingQueue(Collection<? extends E> c) { |
191 |
|
this(Integer.MAX_VALUE); |
192 |
< |
for (Iterator<? extends E> it = c.iterator(); it.hasNext();) |
193 |
< |
add(it.next()); |
192 |
> |
for (E e : c) |
193 |
> |
add(e); |
194 |
|
} |
195 |
|
|
196 |
|
|
525 |
|
fullyLock(); |
526 |
|
try { |
527 |
|
head.next = null; |
528 |
< |
head.item = null; |
529 |
< |
last = head; |
528 |
> |
assert head.item == null; |
529 |
> |
last = head; |
530 |
|
if (count.getAndSet(0) == capacity) |
531 |
|
notFull.signalAll(); |
532 |
|
} finally { |
544 |
|
try { |
545 |
|
first = head.next; |
546 |
|
head.next = null; |
547 |
< |
last = head; |
547 |
> |
assert head.item == null; |
548 |
> |
last = head; |
549 |
|
if (count.getAndSet(0) == capacity) |
550 |
|
notFull.signalAll(); |
551 |
|
} finally { |
558 |
|
p.item = null; |
559 |
|
++n; |
560 |
|
} |
560 |
– |
head.item = null; // Just for GC, so OK if not within lock |
561 |
|
return n; |
562 |
|
} |
563 |
|
|
566 |
|
throw new NullPointerException(); |
567 |
|
if (c == this) |
568 |
|
throw new IllegalArgumentException(); |
569 |
– |
if (maxElements <= 0) |
570 |
– |
return 0; |
569 |
|
fullyLock(); |
570 |
|
try { |
571 |
|
int n = 0; |
578 |
|
} |
579 |
|
if (n != 0) { |
580 |
|
head.next = p; |
581 |
< |
head.item = null; |
582 |
< |
if (p == null) |
583 |
< |
last = head; |
581 |
> |
assert head.item == null; |
582 |
> |
if (p == null) |
583 |
> |
last = head; |
584 |
|
if (count.getAndAdd(-n) == capacity) |
585 |
|
notFull.signalAll(); |
586 |
|
} |