MCPcopy Create free account
hub / github.com/antlr/codebuff / LongAdder

Class LongAdder

output/java_guava/1.4.17/LongAdder.java:50–236  ·  view source on GitHub ↗

One or more variables that together maintain an initially zero long sum. When updates (method #add) are contended across threads, the set of variables may grow dynamically to reduce contention. Method #sum (or, equivalently, #longValue) returns the current total comb

Source from the content-addressed store, hash-verified

48
49
50@GwtCompatible(emulated = true)
51final class LongAdder extends Striped64 implements Serializable, LongAddable {
52 private static final long serialVersionUID = 7249069246863182397L;
53
54 /**
55 * Version of plus for use in retryUpdate
56 */
57 final long fn(long v, long x) {
58 return v + x;
59 }
60
61 /**
62 * Creates a new adder with initial sum of zero.
63 */
64
65
66 public LongAdder() {}
67
68 /**
69 * Adds the given value.
70 *
71 * @param x the value to add
72 */
73
74
75 public void add(long x) {
76 Cell[] as;
77 long b, v;
78 int[] hc;
79 Cell a;
80 int n;
81 if ((as = cells) != null || !casBase(b = base, b + x)) {
82 boolean uncontended = true;
83 if ((hc = threadHashCode.get()) == null || as == null || (n = as.length) < 1
84
85 || (a = as[(n - 1) & hc[0]]) == null || !(uncontended = a.cas(v = a.value, v + x))) retryUpdate(x, hc, uncontended);
86 }
87 }
88
89 /**
90 * Equivalent to {@code add(1)}.
91 */
92
93
94 public void increment() {
95 add(1L);
96 }
97
98 /**
99 * Equivalent to {@code add(-1)}.
100 */
101
102
103 public void decrement() {
104 add(-1L);
105 }
106
107 /**

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected