300 |
|
* handling of sentinel values. Callers from public methods decode |
301 |
|
* and cast accordingly. |
302 |
|
* |
303 |
< |
* @param item the (nonnull) item to exchange |
303 |
> |
* @param item the (non-null) item to exchange |
304 |
|
* @param timed true if the wait is timed |
305 |
|
* @param nanos if timed, the maximum wait time |
306 |
|
* @return the other thread's item, or CANCEL if interrupted or timed out |
318 |
|
else if ((y = slot.get()) != null && // Try to fulfill |
319 |
|
slot.compareAndSet(y, null)) { |
320 |
|
Node you = (Node)y; // Transfer item |
321 |
< |
if (you.compareAndSet(null, me.item)) { |
321 |
> |
if (you.compareAndSet(null, item)) { |
322 |
|
LockSupport.unpark(you.waiter); |
323 |
|
return you.item; |
324 |
|
} // Else cancelled; continue |
330 |
|
Object v = spinWait(me, slot); // Spin wait for non-0 |
331 |
|
if (v != CANCEL) |
332 |
|
return v; |
333 |
< |
me = new Node(me.item); // Throw away cancelled node |
333 |
> |
me = new Node(item); // Throw away cancelled node |
334 |
|
int m = max.get(); |
335 |
|
if (m > (index >>>= 1)) // Decrease index |
336 |
|
max.compareAndSet(m, m - 1); // Maybe shrink table |
391 |
|
// Create slot outside of lock to narrow sync region |
392 |
|
Slot newSlot = new Slot(); |
393 |
|
Slot[] a = arena; |
394 |
< |
synchronized(a) { |
394 |
> |
synchronized (a) { |
395 |
|
if (a[index] == null) |
396 |
|
a[index] = newSlot; |
397 |
|
} |