35 |
|
* <p><em>jsr166e note: This class is targeted to be placed in |
36 |
|
* java.util.concurrent.atomic<em> |
37 |
|
* |
38 |
+ |
* @since 1.8 |
39 |
|
* @author Doug Lea |
40 |
|
*/ |
41 |
|
public class LongAdder extends Striped64 implements Serializable { |
93 |
|
* @return the sum |
94 |
|
*/ |
95 |
|
public long sum() { |
95 |
– |
Cell[] as = cells; |
96 |
|
long sum = base; |
97 |
+ |
Cell[] as = cells; |
98 |
|
if (as != null) { |
99 |
|
int n = as.length; |
100 |
|
for (int i = 0; i < n; ++i) { |
128 |
|
* @return the sum |
129 |
|
*/ |
130 |
|
public long sumThenReset() { |
130 |
– |
Cell[] as = cells; |
131 |
|
long sum = base; |
132 |
+ |
Cell[] as = cells; |
133 |
|
base = 0L; |
134 |
|
if (as != null) { |
135 |
|
int n = as.length; |
136 |
|
for (int i = 0; i < n; ++i) { |
137 |
|
Cell a = as[i]; |
138 |
|
if (a != null) { |
139 |
< |
long v = a.value; |
139 |
> |
sum += a.value; |
140 |
|
a.value = 0L; |
140 |
– |
sum += v; |
141 |
|
} |
142 |
|
} |
143 |
|
} |
146 |
|
|
147 |
|
/** |
148 |
|
* Returns the String representation of the {@link #sum}. |
149 |
< |
* @return the String representation of the {@link #sum}. |
149 |
> |
* @return the String representation of the {@link #sum} |
150 |
|
*/ |
151 |
|
public String toString() { |
152 |
|
return Long.toString(sum()); |