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

Comparing jsr166/src/jsr166e/StripedAdder.java (file contents):
Revision 1.1 by dl, Wed Jul 20 15:00:56 2011 UTC vs.
Revision 1.2 by jsr166, Wed Jul 20 16:06:19 2011 UTC

# Line 22 | Line 22 | import java.io.ObjectOutputStream;
22   * <em>NOT</em> an atomic snapshot (concurrent updates may occur while
23   * the sum is being calculated), and so cannot be used alone for
24   * fine-grained synchronization control.
25 < *
25 > *
26   * <p> This class may be applicable when many threads frequently
27   * update a common sum that is used for purposes such as collecting
28   * statistics. In this case, performance may be significantly faster
# Line 31 | Line 31 | import java.io.ObjectOutputStream;
31   * only one thread can ever update the sum, performance may be
32   * significantly slower than just updating a local variable.
33   *
34 < * @author Doug Lea
34 > * @author Doug Lea
35   */
36   public class StripedAdder implements Serializable {
37      private static final long serialVersionUID = 7249069246863182397L;
# Line 52 | Line 52 | public class StripedAdder implements Ser
52       * candidate Adder.
53       */
54  
55 <    /**
55 >    /**
56       * Number of processors, to place a cap on table growth.
57       */
58      static final int NCPU = Runtime.getRuntime().availableProcessors();
# Line 66 | Line 66 | public class StripedAdder implements Ser
66          Adder(long x) { super(x); }
67      }
68  
69 <    /**
69 >    /**
70       * Holder for the thread-local hash code.
71       */
72      static final class HashCode {
# Line 79 | Line 79 | public class StripedAdder implements Ser
79       */
80      static final class ThreadHashCode extends ThreadLocal<HashCode> {
81          static final Random rng = new Random();
82 <        public HashCode initialValue() {
82 >        public HashCode initialValue() {
83              int h = rng.nextInt();
84              return new HashCode((h == 0) ? 1 : h); // ensure nonzero
85          }
# Line 107 | Line 107 | public class StripedAdder implements Ser
107      /**
108       * Marsaglia XorShift for rehashing on collisions
109       */
110 <    private static int xorShift(int r) {
110 >    private static int xorShift(int r) {
111          r ^= r << 13;
112          r ^= r >>> 17;
113          return r ^ (r << 5);
# Line 172 | Line 172 | public class StripedAdder implements Ser
172       * Returns an estimate of the current sum.  The result is
173       * calculated by summing multiple variables, so may not be
174       * accurate if updates occur concurrently with this method.
175 <     *
175 >     *
176       * @return the estimated sum
177       */
178      public long sum() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines