138 |
|
/** |
139 |
|
* The collision arena. arena[0] is used as the top of the stack. |
140 |
|
* The remainder is used as the collision elimination space. |
141 |
– |
* Each slot holds an AtomicReference<Node>, but this cannot be |
142 |
– |
* expressed for arrays, so elements are casted on each use. |
141 |
|
*/ |
142 |
|
private final AtomicReference<Node>[] arena; |
143 |
|
|
215 |
|
} |
216 |
|
|
217 |
|
/** |
218 |
< |
* Returns a random delay less than (base times (2 raised to backoff)) |
218 |
> |
* Returns a random delay less than (base times (2 raised to backoff)). |
219 |
|
*/ |
220 |
|
private long randomDelay(int backoff) { |
221 |
|
return ((BACKOFF_BASE << backoff) - 1) & random.nextInt(); |
233 |
|
|
234 |
|
/** The element offered by the Thread creating this node. */ |
235 |
|
final Object item; |
236 |
+ |
|
237 |
|
/** The Thread creating this node. */ |
238 |
|
final Thread waiter; |
239 |
|
|
240 |
|
/** |
241 |
|
* Creates node with given item and empty hole. |
242 |
< |
* @param item the item. |
242 |
> |
* |
243 |
> |
* @param item the item |
244 |
|
*/ |
245 |
|
Node(Object item) { |
246 |
|
this.item = item; |
249 |
|
|
250 |
|
/** |
251 |
|
* Tries to fill in hole. On success, wakes up the waiter. |
252 |
< |
* @param val the value to place in hole. |
253 |
< |
* @return on success, the item; on failure, FAIL. |
252 |
> |
* |
253 |
> |
* @param val the value to place in hole |
254 |
> |
* @return on success, the item; on failure, FAIL |
255 |
|
*/ |
256 |
|
Object fillHole(Object val) { |
257 |
|
if (compareAndSet(null, val)) { |
295 |
|
|
296 |
|
/** |
297 |
|
* Waits for another thread to arrive at this exchange point (unless |
298 |
< |
* it is {@link Thread#interrupt interrupted}), |
298 |
> |
* the current thread is {@link Thread#interrupt interrupted}), |
299 |
|
* and then transfers the given object to it, receiving its object |
300 |
|
* in return. |
301 |
|
* |
336 |
|
|
337 |
|
/** |
338 |
|
* Waits for another thread to arrive at this exchange point (unless |
339 |
< |
* it is {@link Thread#interrupt interrupted}, or the specified waiting |
340 |
< |
* time elapses), |
341 |
< |
* and then transfers the given object to it, receiving its object |
341 |
< |
* in return. |
339 |
> |
* the current thread is {@link Thread#interrupt interrupted} or |
340 |
> |
* the specified waiting time elapses), and then transfers the given |
341 |
> |
* object to it, receiving its object in return. |
342 |
|
* |
343 |
|
* <p>If another thread is already waiting at the exchange point then |
344 |
|
* it is resumed for thread scheduling purposes and receives the object |