--- a/src/java.base/share/classes/java/util/concurrent/atomic/LongAccumulator.java Fri Dec 08 15:22:58 2017 -0800
+++ b/src/java.base/share/classes/java/util/concurrent/atomic/LongAccumulator.java Fri Dec 08 15:26:56 2017 -0800
@@ -103,17 +103,17 @@
* @param x the value
*/
public void accumulate(long x) {
- Cell[] as; long b, v, r; int m; Cell a;
- if ((as = cells) != null
+ Cell[] cs; long b, v, r; int m; Cell c;
+ if ((cs = cells) != null
|| ((r = function.applyAsLong(b = base, x)) != b
&& !casBase(b, r))) {
boolean uncontended = true;
- if (as == null
- || (m = as.length - 1) < 0
- || (a = as[getProbe() & m]) == null
+ if (cs == null
+ || (m = cs.length - 1) < 0
+ || (c = cs[getProbe() & m]) == null
|| !(uncontended =
- (r = function.applyAsLong(v = a.value, x)) == v
- || a.cas(v, r)))
+ (r = function.applyAsLong(v = c.value, x)) == v
+ || c.cas(v, r)))
longAccumulate(x, function, uncontended);
}
}
@@ -128,12 +128,12 @@
* @return the current value
*/
public long get() {
- Cell[] as = cells;
+ Cell[] cs = cells;
long result = base;
- if (as != null) {
- for (Cell a : as)
- if (a != null)
- result = function.applyAsLong(result, a.value);
+ if (cs != null) {
+ for (Cell c : cs)
+ if (c != null)
+ result = function.applyAsLong(result, c.value);
}
return result;
}
@@ -147,12 +147,12 @@
* updating.
*/
public void reset() {
- Cell[] as = cells;
+ Cell[] cs = cells;
base = identity;
- if (as != null) {
- for (Cell a : as)
- if (a != null)
- a.reset(identity);
+ if (cs != null) {
+ for (Cell c : cs)
+ if (c != null)
+ c.reset(identity);
}
}
@@ -167,14 +167,12 @@
* @return the value before reset
*/
public long getThenReset() {
- Cell[] as = cells;
- long result = base;
- base = identity;
- if (as != null) {
- for (Cell a : as) {
- if (a != null) {
- long v = a.value;
- a.reset(identity);
+ Cell[] cs = cells;
+ long result = getAndSetBase(identity);
+ if (cs != null) {
+ for (Cell c : cs) {
+ if (c != null) {
+ long v = c.getAndSet(identity);
result = function.applyAsLong(result, v);
}
}