79 |
|
* Oveview: The core algorithm is, for an exchange "slot", |
80 |
|
* and a participant (caller) with an item: |
81 |
|
* |
82 |
< |
* for(;;) { |
82 |
> |
* for (;;) { |
83 |
|
* if (slot is empty) { // offer |
84 |
|
* place item in a Node; |
85 |
|
* if (can CAS slot from empty to node) { |
348 |
|
else if (i <= (m = (b = bound) & MMASK) && q == null) { |
349 |
|
p.item = item; // offer |
350 |
|
if (U.compareAndSwapObject(a, j, null, p)) { |
351 |
< |
long end = (timed && m == 0)? System.nanoTime() + ns : 0L; |
351 |
> |
long end = (timed && m == 0) ? System.nanoTime() + ns : 0L; |
352 |
|
Thread t = Thread.currentThread(); // wait |
353 |
|
for (int h = p.hash, spins = SPINS;;) { |
354 |
|
Object v = p.match; |
457 |
|
|
458 |
|
// await release |
459 |
|
int h = p.hash; |
460 |
< |
long end = timed? System.nanoTime() + ns : 0L; |
460 |
> |
long end = timed ? System.nanoTime() + ns : 0L; |
461 |
|
int spins = (NCPU > 1) ? SPINS : 1; |
462 |
|
Object v; |
463 |
|
while ((v = p.match) == null) { |
533 |
|
@SuppressWarnings("unchecked") |
534 |
|
public V exchange(V x) throws InterruptedException { |
535 |
|
Object v; |
536 |
< |
Object item = (x == null)? NULL_ITEM : x; // translate null args |
536 |
> |
Object item = (x == null) ? NULL_ITEM : x; // translate null args |
537 |
|
if ((arena != null || |
538 |
|
(v = slotExchange(item, false, 0L)) == null) && |
539 |
|
((Thread.interrupted() || // disambiguates null return |
540 |
|
(v = arenaExchange(item, false, 0L)) == null))) |
541 |
|
throw new InterruptedException(); |
542 |
< |
return (v == NULL_ITEM)? null : (V)v; |
542 |
> |
return (v == NULL_ITEM) ? null : (V)v; |
543 |
|
} |
544 |
|
|
545 |
|
/** |
588 |
|
public V exchange(V x, long timeout, TimeUnit unit) |
589 |
|
throws InterruptedException, TimeoutException { |
590 |
|
Object v; |
591 |
< |
Object item = (x == null)? NULL_ITEM : x; |
591 |
> |
Object item = (x == null) ? NULL_ITEM : x; |
592 |
|
long ns = unit.toNanos(timeout); |
593 |
|
if ((arena != null || |
594 |
|
(v = slotExchange(item, true, ns)) == null) && |
597 |
|
throw new InterruptedException(); |
598 |
|
if (v == TIMED_OUT) |
599 |
|
throw new TimeoutException(); |
600 |
< |
return (v == NULL_ITEM)? null : (V)v; |
600 |
> |
return (v == NULL_ITEM) ? null : (V)v; |
601 |
|
} |
602 |
|
|
603 |
|
// Unsafe mechanics |