288 |
|
/** |
289 |
|
* The maximum slot index being used. The value sometimes |
290 |
|
* increases when a thread experiences too many CAS contentions, |
291 |
< |
* and sometimes decreases when a backoff wait elapses. Changes |
291 |
> |
* and sometimes decreases when a spin-wait elapses. Changes |
292 |
|
* are performed only via compareAndSet, to avoid stale values |
293 |
|
* when a thread happens to stall right before setting. |
294 |
|
*/ |
382 |
|
|
383 |
|
/** |
384 |
|
* Creates a new slot at given index. Called only when the slot |
385 |
< |
* appears to be null. Relies on double-check using builtin locks, |
386 |
< |
* since they rarely contend. |
385 |
> |
* appears to be null. Relies on double-check using builtin |
386 |
> |
* locks, since they rarely contend. This in turn relies on the |
387 |
> |
* arena array being declared volatile. |
388 |
|
* |
389 |
|
* @param index the index to add slot at |
390 |
|
*/ |
399 |
|
} |
400 |
|
|
401 |
|
/** |
402 |
< |
* Try to cancel a wait for the given node waiting in the given |
402 |
> |
* Trie to cancel a wait for the given node waiting in the given |
403 |
|
* slot, if so, helping clear the node from its slot to avoid |
404 |
|
* garbage retention. |
405 |
|
* |
410 |
|
private static boolean tryCancel(Node node, Slot slot) { |
411 |
|
if (!node.compareAndSet(null, CANCEL)) |
412 |
|
return false; |
413 |
< |
if (slot.get() == node) |
413 |
> |
if (slot.get() == node) // pre-check to minimize contention |
414 |
|
slot.compareAndSet(node, null); |
415 |
|
return true; |
416 |
|
} |