标签:ice weixin family 方法 cti shadow reg mil 使用
public LongAccumlator(LongBinaryOperator accumulatorFunction,long identity) {
this.function = accumulatorFunction;
base = this.identity = identity;
}
public interface LongBinaryOperator {
long applyAsLong(long left,long right);
}
LongAdder adder = new LongAdder();
LongAccumulator accumulator = new LongAccumulator(new LongBinaryOperator() {
@Override
public long applyAsLong(long left,long right) {
return left + right;
}
}
//LongAdder的add方法
public void add(long x){
Cell[] as;
long b;
long v;
int m;
Cell a;
if(as = cells) != null || !casBase(b = base,b+x)) {
boolean uncontended = true;
if(as == null || (m = as.length -1)<0 || (a = as[getProbe() & m]) == null || !(uncontended = a.cas(v = a.value,v + x))){
longAccumulator(x,null,uncontended);
}
}
}
//LongAccumulator的accumulate方法
public void accumulate(long x){
Cell[] as;
long b;
long v;
int m;
Cell a;
if(as = 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 || !(uncontended = (r = function.applyAsLong(v = a.value,x)) == v|| a.cas(v,r))){
longAccumulator(x,null,uncontended);
}
}
else if(casBase(v = base,((fn==null)?v+x:fn.applyAsLong(v,x)))){
break;
}
https://github.com/ruigege66/ConcurrentJava
标签:ice weixin family 方法 cti shadow reg mil 使用
原文地址:https://www.cnblogs.com/ruigege0000/p/14249271.html