28 |
|
* |
29 |
|
* <p> Method {@link #sum} returns the current combined total across |
30 |
|
* the variables maintaining the sum. This value is <em>NOT</em> an |
31 |
< |
* atomic snapshot: Invocation of <code>sum</code> in the absence of |
31 |
> |
* atomic snapshot: Invocation of {@code sum} in the absence of |
32 |
|
* concurrent updates returns an accurate result, but concurrent |
33 |
|
* updates that occur while the sum is being calculated might not be |
34 |
< |
* incorporated. The sum may also be <code>reset</code> to zero, as |
34 |
> |
* incorporated. The sum may also be {@code reset} to zero, as |
35 |
|
* an alternative to creating a new adder. However, method {@link |
36 |
|
* #reset} is intrinsically racy, so should only be used when it is |
37 |
|
* known that no threads are concurrently updating the sum. |
130 |
|
code = (h == 0) ? 1 : h; |
131 |
|
} |
132 |
|
} |
133 |
< |
|
133 |
> |
|
134 |
|
/** |
135 |
|
* The corresponding ThreadLocal class |
136 |
|
*/ |
146 |
|
*/ |
147 |
|
static final ThreadHashCode threadHashCode = new ThreadHashCode(); |
148 |
|
|
149 |
< |
/** Nomber of CPUS, to place bound on table size */ |
149 |
> |
/** Number of CPUS, to place bound on table size */ |
150 |
|
private static final int NCPU = Runtime.getRuntime().availableProcessors(); |
151 |
|
|
152 |
|
/** |
156 |
|
|
157 |
|
/** |
158 |
|
* Base sum, used mainly when there is no contention, but also as |
159 |
< |
* a fallback during table initializion races. Updated via CAS. |
159 |
> |
* a fallback during table initialization races. Updated via CAS. |
160 |
|
*/ |
161 |
|
private transient volatile long base; |
162 |
|
|
233 |
|
} |
234 |
|
else if (!wasUncontended) // CAS already known to fail |
235 |
|
wasUncontended = true; // Continue after rehash |
236 |
< |
else if (UNSAFE.compareAndSwapLong(a, valueOffset, |
236 |
> |
else if (UNSAFE.compareAndSwapLong(a, valueOffset, |
237 |
|
v = a.value, v + x)) |
238 |
|
break; |
239 |
|
else if (n >= NCPU || cells != as) |
275 |
|
if (init) |
276 |
|
break; |
277 |
|
} |
278 |
< |
else if (UNSAFE.compareAndSwapLong(this, baseOffset, |
278 |
> |
else if (UNSAFE.compareAndSwapLong(this, baseOffset, |
279 |
|
v = base, v + x)) |
280 |
|
break; // Fall back on using base |
281 |
|
} |