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

Comparing jsr166/src/jsr166e/LongAdderTable.java (file contents):
Revision 1.2 by dl, Sun Jul 31 19:24:37 2011 UTC vs.
Revision 1.3 by dl, Mon Aug 29 17:06:20 2011 UTC

# Line 6 | Line 6
6  
7   package jsr166e;
8   import jsr166e.LongAdder;
9 import java.util.concurrent.ConcurrentHashMap;
9   import java.util.Map;
10   import java.util.Set;
11   import java.io.Serializable;
# Line 27 | Line 26 | public class LongAdderTable<K> implement
26      /** Relies on default serialization */
27      private static final long serialVersionUID = 7249369246863182397L;
28  
30    /** Concurrency parameter for map -- we assume high contention */
31    private static final int MAP_SEGMENTS =
32        Math.max(16, Runtime.getRuntime().availableProcessors());
33
29      /** The underlying map */
30 <    private final ConcurrentHashMap<K, LongAdder> map;
30 >    private final ConcurrentHashMapV8<K, LongAdder> map;
31 >
32 >    static final class CreateAdder
33 >        implements ConcurrentHashMapV8.MappingFunction<Object, LongAdder> {
34 >        public LongAdder map(Object unused) { return new LongAdder(); }
35 >    }
36 >
37 >    private static final CreateAdder createAdder = new CreateAdder();
38  
39      /**
40       * Creates a new empty table.
41       */
42      public LongAdderTable() {
43 <        map = new ConcurrentHashMap<K, LongAdder>(16, 0.75f, MAP_SEGMENTS);
43 >        map = new ConcurrentHashMapV8<K, LongAdder>();
44      }
45  
46      /**
# Line 69 | Line 71 | public class LongAdderTable<K> implement
71       */
72      public void add(K key, long x) {
73          LongAdder a = map.get(key);
74 <        if (a == null) {
75 <            LongAdder r = new LongAdder();
74 <            if ((a = map.putIfAbsent(key, r)) == null)
75 <                a = r;
76 <        }
74 >        if (a == null)
75 >            a = map.computeIfAbsent(key, createAdder);
76          a.add(x);
77      }
78  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines