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.12 by jsr166, Sun Jan 6 18:50:00 2013 UTC vs.
Revision 1.17 by jsr166, Mon May 5 20:20:15 2014 UTC

# Line 5 | Line 5
5   */
6  
7   package jsr166e;
8 < import java.util.concurrent.atomic.AtomicLong;
8 >
9   import java.io.IOException;
10 import java.io.Serializable;
10   import java.io.ObjectInputStream;
11   import java.io.ObjectOutputStream;
12 + import java.io.Serializable;
13 + import java.util.concurrent.atomic.AtomicLong;
14  
15   /**
16   * One or more variables that together maintain an initially zero
# Line 58 | Line 59 | public class LongAdder extends Striped64
59       * @param x the value to add
60       */
61      public void add(long x) {
62 <        Cell[] as; long b, v; HashCode hc; Cell a; int n;
62 >        Cell[] as; long b, v; int[] hc; Cell a; int n;
63          if ((as = cells) != null || !casBase(b = base, b + x)) {
64              boolean uncontended = true;
65 <            int h = (hc = threadHashCode.get()).code;
66 <            if (as == null || (n = as.length) < 1 ||
67 <                (a = as[(n - 1) & h]) == null ||
65 >            if ((hc = threadHashCode.get()) == null ||
66 >                as == null || (n = as.length) < 1 ||
67 >                (a = as[(n - 1) & hc[0]]) == null ||
68                  !(uncontended = a.cas(v = a.value, v + x)))
69                  retryUpdate(x, hc, uncontended);
70          }
# Line 85 | Line 86 | public class LongAdder extends Striped64
86  
87      /**
88       * Returns the current sum.  The returned value is <em>NOT</em> an
89 <     * atomic snapshot: invocation in the absence of concurrent
89 >     * atomic snapshot; invocation in the absence of concurrent
90       * updates returns an accurate result, but concurrent updates that
91       * occur while the sum is being calculated might not be
92       * incorporated.
# Line 185 | Line 186 | public class LongAdder extends Striped64
186          return (double)sum();
187      }
188  
189 <    private void writeObject(java.io.ObjectOutputStream s)
189 <        throws java.io.IOException {
189 >    private void writeObject(ObjectOutputStream s) throws IOException {
190          s.defaultWriteObject();
191          s.writeLong(sum());
192      }
193  
194      private void readObject(ObjectInputStream s)
195 <        throws IOException, ClassNotFoundException {
195 >            throws IOException, ClassNotFoundException {
196          s.defaultReadObject();
197          busy = 0;
198          cells = null;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines