387 |
|
/** |
388 |
|
* Adds the specified element to this queue, waiting if necessary for |
389 |
|
* another thread to receive it. |
390 |
< |
* @param o the element to add |
390 |
> |
* @param e the element to add |
391 |
|
* @throws InterruptedException if interrupted while waiting. |
392 |
|
* @throws NullPointerException if the specified element is <tt>null</tt>. |
393 |
|
*/ |
394 |
< |
public void put(E o) throws InterruptedException { |
395 |
< |
if (o == null) throw new NullPointerException(); |
394 |
> |
public void put(E e) throws InterruptedException { |
395 |
> |
if (e == null) throw new NullPointerException(); |
396 |
|
final ReentrantLock qlock = this.qlock; |
397 |
|
|
398 |
|
for (;;) { |
403 |
|
try { |
404 |
|
node = waitingConsumers.deq(); |
405 |
|
if ( (mustWait = (node == null)) ) |
406 |
< |
node = waitingProducers.enq(o); |
406 |
> |
node = waitingProducers.enq(e); |
407 |
|
} finally { |
408 |
|
qlock.unlock(); |
409 |
|
} |
418 |
|
} |
419 |
|
} |
420 |
|
|
421 |
< |
else if (node.setItem(o)) |
421 |
> |
else if (node.setItem(e)) |
422 |
|
return; |
423 |
|
|
424 |
|
// else consumer cancelled, so retry |
428 |
|
/** |
429 |
|
* Inserts the specified element into this queue, waiting if necessary |
430 |
|
* up to the specified wait time for another thread to receive it. |
431 |
< |
* @param o the element to add |
431 |
> |
* @param e the element to add |
432 |
|
* @param timeout how long to wait before giving up, in units of |
433 |
|
* <tt>unit</tt> |
434 |
|
* @param unit a <tt>TimeUnit</tt> determining how to interpret the |
438 |
|
* @throws InterruptedException if interrupted while waiting. |
439 |
|
* @throws NullPointerException if the specified element is <tt>null</tt>. |
440 |
|
*/ |
441 |
< |
public boolean offer(E o, long timeout, TimeUnit unit) throws InterruptedException { |
442 |
< |
if (o == null) throw new NullPointerException(); |
441 |
> |
public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { |
442 |
> |
if (e == null) throw new NullPointerException(); |
443 |
|
long nanos = unit.toNanos(timeout); |
444 |
|
final ReentrantLock qlock = this.qlock; |
445 |
|
for (;;) { |
450 |
|
try { |
451 |
|
node = waitingConsumers.deq(); |
452 |
|
if ( (mustWait = (node == null)) ) |
453 |
< |
node = waitingProducers.enq(o); |
453 |
> |
node = waitingProducers.enq(e); |
454 |
|
} finally { |
455 |
|
qlock.unlock(); |
456 |
|
} |
467 |
|
} |
468 |
|
} |
469 |
|
|
470 |
< |
else if (node.setItem(o)) |
470 |
> |
else if (node.setItem(e)) |
471 |
|
return true; |
472 |
|
|
473 |
|
// else consumer cancelled, so retry |
570 |
|
* Inserts the specified element into this queue, if another thread is |
571 |
|
* waiting to receive it. |
572 |
|
* |
573 |
< |
* @param o the element to add. |
573 |
> |
* @param e 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>. |
577 |
|
*/ |
578 |
< |
public boolean offer(E o) { |
579 |
< |
if (o == null) throw new NullPointerException(); |
578 |
> |
public boolean offer(E e) { |
579 |
> |
if (e == null) throw new NullPointerException(); |
580 |
|
final ReentrantLock qlock = this.qlock; |
581 |
|
|
582 |
|
for (;;) { |
590 |
|
if (node == null) |
591 |
|
return false; |
592 |
|
|
593 |
< |
else if (node.setItem(o)) |
593 |
> |
else if (node.setItem(e)) |
594 |
|
return true; |
595 |
|
// else retry |
596 |
|
} |