ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166e/LongAdder.java
(Generate patch)

Comparing jsr166/src/jsr166e/LongAdder.java (file contents):
Revision 1.5 by dl, Tue Aug 2 18:04:12 2011 UTC vs.
Revision 1.10 by jsr166, Sun Nov 18 18:03:10 2012 UTC

# Line 19 | Line 19 | import java.io.ObjectOutputStream;
19   * #longValue}) returns the current total combined across the
20   * variables maintaining the sum.
21   *
22 < * <p> This class is usually preferable to {@link AtomicLong} when
22 > * <p>This class is usually preferable to {@link AtomicLong} when
23   * multiple threads update a common sum that is used for purposes such
24   * as collecting statistics, not for fine-grained synchronization
25   * control.  Under low update contention, the two classes have similar
# Line 33 | Line 33 | import java.io.ObjectOutputStream;
33   * collection keys.
34   *
35   * <p><em>jsr166e note: This class is targeted to be placed in
36 < * java.util.concurrent.atomic<em>
36 > * java.util.concurrent.atomic.</em>
37   *
38 + * @since 1.8
39   * @author Doug Lea
40   */
41   public class LongAdder extends Striped64 implements Serializable {
# Line 92 | Line 93 | public class LongAdder extends Striped64
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) {
# Line 127 | Line 128 | public class LongAdder extends Striped64
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          }
# Line 146 | Line 146 | public class LongAdder extends Striped64
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());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines