39 |
|
* |
40 |
|
* <p>This class and its iterator implement all of the |
41 |
|
* <em>optional</em> methods of the {@link Collection} and {@link |
42 |
< |
* Iterator} interfaces. |
42 |
> |
* Iterator} interfaces. |
43 |
|
* |
44 |
|
* <p>This class is a member of the |
45 |
|
* <a href="{@docRoot}/../guide/collections/index.html"> |
116 |
|
* in order to recover fairness settings when deserialized. |
117 |
|
*/ |
118 |
|
static abstract class WaitQueue implements java.io.Serializable { |
119 |
< |
/** Create, add, and return node for x */ |
119 |
> |
/** Creates, adds, and returns node for x. */ |
120 |
|
abstract Node enq(Object x); |
121 |
< |
/** Remove and return node, or null if empty */ |
121 |
> |
/** Removes and returns node, or null if empty. */ |
122 |
|
abstract Node deq(); |
123 |
< |
/** Remove a cancelled node to avoid garbage retention. */ |
123 |
> |
/** Removes a cancelled node to avoid garbage retention. */ |
124 |
|
abstract void unlink(Node node); |
125 |
< |
/** Return true if a cancelled node might be on queue */ |
125 |
> |
/** Returns true if a cancelled node might be on queue. */ |
126 |
|
abstract boolean shouldUnlink(Node node); |
127 |
|
} |
128 |
|
|
164 |
|
while (p != null) { |
165 |
|
if (p == node) { |
166 |
|
Node next = p.next; |
167 |
< |
if (trail == null) |
167 |
> |
if (trail == null) |
168 |
|
head = next; |
169 |
|
else |
170 |
|
trail.next = next; |
210 |
|
while (p != null) { |
211 |
|
if (p == node) { |
212 |
|
Node next = p.next; |
213 |
< |
if (trail == null) |
213 |
> |
if (trail == null) |
214 |
|
head = next; |
215 |
|
else |
216 |
|
trail.next = next; |
225 |
|
/* |
226 |
|
* Unlink the given node from consumer queue. Called by cancelled |
227 |
|
* (timeout, interrupt) waiters to avoid garbage retention in the |
228 |
< |
* absence of producers. |
228 |
> |
* absence of producers. |
229 |
|
*/ |
230 |
|
private void unlinkCancelledConsumer(Node node) { |
231 |
|
// Use a form of double-check to avoid unnecessary locking and |
234 |
|
if (waitingConsumers.shouldUnlink(node)) { |
235 |
|
qlock.lock(); |
236 |
|
try { |
237 |
< |
if (waitingConsumers.shouldUnlink(node)) |
237 |
> |
if (waitingConsumers.shouldUnlink(node)) |
238 |
|
waitingConsumers.unlink(node); |
239 |
|
} finally { |
240 |
|
qlock.unlock(); |
250 |
|
if (waitingProducers.shouldUnlink(node)) { |
251 |
|
qlock.lock(); |
252 |
|
try { |
253 |
< |
if (waitingProducers.shouldUnlink(node)) |
253 |
> |
if (waitingProducers.shouldUnlink(node)) |
254 |
|
waitingProducers.unlink(node); |
255 |
|
} finally { |
256 |
|
qlock.unlock(); |
257 |
|
} |
258 |
|
} |
259 |
|
} |
260 |
< |
|
260 |
> |
|
261 |
|
/** |
262 |
|
* Nodes each maintain an item and handle waits and signals for |
263 |
|
* getting and setting it. The class extends |
308 |
|
* Tries to cancel on interrupt; if so rethrowing, |
309 |
|
* else setting interrupt state |
310 |
|
*/ |
311 |
< |
private void checkCancellationOnInterrupt(InterruptedException ie) |
311 |
> |
private void checkCancellationOnInterrupt(InterruptedException ie) |
312 |
|
throws InterruptedException { |
313 |
< |
if (release(CANCEL)) |
313 |
> |
if (release(CANCEL)) |
314 |
|
throw ie; |
315 |
|
Thread.currentThread().interrupt(); |
316 |
|
} |
458 |
|
if (mustWait) { |
459 |
|
try { |
460 |
|
boolean x = node.waitForTake(nanos); |
461 |
< |
if (!x) |
461 |
> |
if (!x) |
462 |
|
unlinkCancelledProducer(node); |
463 |
|
return x; |
464 |
|
} catch (InterruptedException ex) { |
547 |
|
if (mustWait) { |
548 |
|
try { |
549 |
|
Object x = node.waitForPut(nanos); |
550 |
< |
if (x == null) |
550 |
> |
if (x == null) |
551 |
|
unlinkCancelledConsumer(node); |
552 |
|
return (E)x; |
553 |
|
} catch (InterruptedException ex) { |
573 |
|
* @param o the element to add. |
574 |
|
* @return <tt>true</tt> if it was possible to add the element to |
575 |
|
* this queue, else <tt>false</tt> |
576 |
< |
* @throws NullPointerException if the specified element is <tt>null</tt> |
576 |
> |
* @throws NullPointerException if the specified element is <tt>null</tt>. |
577 |
|
*/ |
578 |
|
public boolean offer(E o) { |
579 |
|
if (o == null) throw new NullPointerException(); |
626 |
|
} |
627 |
|
|
628 |
|
/** |
629 |
< |
* Always returns <tt>true</tt>. |
629 |
> |
* Always returns <tt>true</tt>. |
630 |
|
* A <tt>SynchronousQueue</tt> has no internal capacity. |
631 |
|
* @return <tt>true</tt> |
632 |
|
*/ |
710 |
|
} |
711 |
|
|
712 |
|
/** |
713 |
< |
* Always returns <tt>null</tt>. |
713 |
> |
* Always returns <tt>null</tt>. |
714 |
|
* A <tt>SynchronousQueue</tt> does not return elements |
715 |
|
* unless actively waited on. |
716 |
|
* @return <tt>null</tt> |
792 |
|
return n; |
793 |
|
} |
794 |
|
} |
795 |
– |
|
796 |
– |
|
797 |
– |
|
798 |
– |
|
799 |
– |
|