@Override public int refCnt() { return realRefCnt(refCntUpdater.get(this)); }
@Override public int refCnt() { return realRefCnt(refCntUpdater.get(this)); }
private ReferenceCounted retain0(final int increment) { // all changes to the raw count are 2x the "real" change int adjustedIncrement = increment << 1; // overflow OK here int oldRef = refCntUpdater.getAndAdd(this, adjustedIncrement); if ((oldRef & 1) != 0) { throw new IllegalReferenceCountException(0, increment); } // don't pass 0! if ((oldRef <= 0 && oldRef + adjustedIncrement >= 0) || (oldRef >= 0 && oldRef + adjustedIncrement < oldRef)) { // overflow case refCntUpdater.getAndAdd(this, -adjustedIncrement); throw new IllegalReferenceCountException(realRefCnt(oldRef), increment); } return this; }
private ReferenceCounted retain0(final int increment) { // all changes to the raw count are 2x the "real" change int adjustedIncrement = increment << 1; // overflow OK here int oldRef = refCntUpdater.getAndAdd(this, adjustedIncrement); if ((oldRef & 1) != 0) { throw new IllegalReferenceCountException(0, increment); } // don't pass 0! if ((oldRef <= 0 && oldRef + adjustedIncrement >= 0) || (oldRef >= 0 && oldRef + adjustedIncrement < oldRef)) { // overflow case refCntUpdater.getAndAdd(this, -adjustedIncrement); throw new IllegalReferenceCountException(realRefCnt(oldRef), increment); } return this; }
@Override public int refCnt() { return realRefCnt(refCntUpdater.get(this)); }
private ReferenceCounted retain0(final int increment) { // all changes to the raw count are 2x the "real" change int adjustedIncrement = increment << 1; // overflow OK here int oldRef = refCntUpdater.getAndAdd(this, adjustedIncrement); if ((oldRef & 1) != 0) { throw new IllegalReferenceCountException(0, increment); } // don't pass 0! if ((oldRef <= 0 && oldRef + adjustedIncrement >= 0) || (oldRef >= 0 && oldRef + adjustedIncrement < oldRef)) { // overflow case refCntUpdater.getAndAdd(this, -adjustedIncrement); throw new IllegalReferenceCountException(realRefCnt(oldRef), increment); } return this; }