590 |
|
* @throws InterruptedException if the current thread was |
591 |
|
* interrupted while waiting |
592 |
|
*/ |
593 |
+ |
@SuppressWarnings("unchecked") |
594 |
|
public V exchange(V x) throws InterruptedException { |
595 |
|
if (!Thread.interrupted()) { |
596 |
|
Object o = doExchange((x == null) ? NULL_ITEM : x, false, 0); |
597 |
|
if (o == NULL_ITEM) |
598 |
|
return null; |
599 |
< |
if (o != CANCEL) { |
600 |
< |
@SuppressWarnings("unchecked") V v = (V)o; |
600 |
< |
return v; |
601 |
< |
} |
599 |
> |
if (o != CANCEL) |
600 |
> |
return (V)o; |
601 |
|
Thread.interrupted(); // Clear interrupt status on IE throw |
602 |
|
} |
603 |
|
throw new InterruptedException(); |
645 |
|
* @throws TimeoutException if the specified waiting time elapses |
646 |
|
* before another thread enters the exchange |
647 |
|
*/ |
648 |
+ |
@SuppressWarnings("unchecked") |
649 |
|
public V exchange(V x, long timeout, TimeUnit unit) |
650 |
|
throws InterruptedException, TimeoutException { |
651 |
|
if (!Thread.interrupted()) { |
653 |
|
true, unit.toNanos(timeout)); |
654 |
|
if (o == NULL_ITEM) |
655 |
|
return null; |
656 |
< |
if (o != CANCEL) { |
657 |
< |
@SuppressWarnings("unchecked") V v = (V)o; |
658 |
< |
return v; |
659 |
< |
} |
656 |
> |
if (o != CANCEL) |
657 |
> |
return (V)o; |
658 |
|
if (!Thread.interrupted()) |
659 |
|
throw new TimeoutException(); |
660 |
|
} |