Refine search
@SuppressWarnings("deprecation") private Component newComponent(ByteBuf buf, int offset) { if (checkAccessible && buf.refCnt() == 0) { throw new IllegalReferenceCountException(0); } int srcIndex = buf.readerIndex(), len = buf.readableBytes(); ByteBuf slice = null; if (buf instanceof AbstractUnpooledSlicedByteBuf) { srcIndex += ((AbstractUnpooledSlicedByteBuf) buf).idx(0); slice = buf; buf = buf.unwrap(); } else if (buf instanceof PooledSlicedByteBuf) { srcIndex += ((PooledSlicedByteBuf) buf).adjustment; slice = buf; buf = buf.unwrap(); } return new Component(buf.order(ByteOrder.BIG_ENDIAN), srcIndex, offset, len, slice); }
private boolean retryRelease0(int decrement) { for (;;) { int rawCnt = refCntUpdater.get(this), realCnt = toLiveRealCnt(rawCnt, decrement); if (decrement == realCnt) { if (refCntUpdater.compareAndSet(this, rawCnt, 1)) { deallocate(); return true; } } else if (decrement < realCnt) { // all changes to the raw count are 2x the "real" change if (refCntUpdater.compareAndSet(this, rawCnt, rawCnt - (decrement << 1))) { return false; } } else { throw new IllegalReferenceCountException(realCnt, -decrement); } Thread.yield(); // this benefits throughput under high contention } }
@Override public ByteBuf content() { if (data.refCnt() <= 0) { throw new IllegalReferenceCountException(data.refCnt()); } return data; }
private ReferenceCounted retain0(int increment) { for (;;) { int refCnt = this.refCnt; final int nextCnt = refCnt + increment; // Ensure we not resurrect (which means the refCnt was 0) and also that we encountered an overflow. if (nextCnt <= increment) { throw new IllegalReferenceCountException(refCnt, increment); } if (refCntUpdater.compareAndSet(this, refCnt, nextCnt)) { break; } } 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; }
/** * Like {@link #realRefCnt(int)} but throws if refCnt == 0 */ private static int toLiveRealCnt(int rawCnt, int decrement) { if ((rawCnt & 1) == 0) { return rawCnt >>> 1; } // odd rawCnt => already deallocated throw new IllegalReferenceCountException(0, -decrement); }
private boolean retryRelease0(int decrement) { for (;;) { int rawCnt = refCntUpdater.get(this), realCnt = toLiveRealCnt(rawCnt, decrement); if (decrement == realCnt) { if (refCntUpdater.compareAndSet(this, rawCnt, 1)) { deallocate(); return true; } } else if (decrement < realCnt) { // all changes to the raw count are 2x the "real" change if (refCntUpdater.compareAndSet(this, rawCnt, rawCnt - (decrement << 1))) { return false; } } else { throw new IllegalReferenceCountException(realCnt, -decrement); } Thread.yield(); // this benefits throughput under high contention } }
@Override public ByteBuf content() { if (data.refCnt() <= 0) { throw new IllegalReferenceCountException(data.refCnt()); } return data; }
private boolean release0(int decrement) { for (;;) { int refCnt = this.refCnt; if (refCnt < decrement) { throw new IllegalReferenceCountException(refCnt, -decrement); } if (refCntUpdater.compareAndSet(this, refCnt, refCnt - decrement)) { if (refCnt == decrement) { deallocate(); return true; } return false; } } }
private ByteBuf 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; }
/** * Like {@link #realRefCnt(int)} but throws if refCnt == 0 */ private static int toLiveRealCnt(int rawCnt, int decrement) { if ((rawCnt & 1) == 0) { return rawCnt >>> 1; } // odd rawCnt => already deallocated throw new IllegalReferenceCountException(0, -decrement); }
@SuppressWarnings("deprecation") private Component newComponent(ByteBuf buf, int offset) { if (checkAccessible && buf.refCnt() == 0) { throw new IllegalReferenceCountException(0); } int srcIndex = buf.readerIndex(), len = buf.readableBytes(); ByteBuf slice = null; if (buf instanceof AbstractUnpooledSlicedByteBuf) { srcIndex += ((AbstractUnpooledSlicedByteBuf) buf).idx(0); slice = buf; buf = buf.unwrap(); } else if (buf instanceof PooledSlicedByteBuf) { srcIndex += ((PooledSlicedByteBuf) buf).adjustment; slice = buf; buf = buf.unwrap(); } return new Component(buf.order(ByteOrder.BIG_ENDIAN), srcIndex, offset, len, slice); }
private boolean retryRelease0(int decrement) { for (;;) { int rawCnt = refCntUpdater.get(this), realCnt = toLiveRealCnt(rawCnt, decrement); if (decrement == realCnt) { if (refCntUpdater.compareAndSet(this, rawCnt, 1)) { deallocate(); return true; } } else if (decrement < realCnt) { // all changes to the raw count are 2x the "real" change if (refCntUpdater.compareAndSet(this, rawCnt, rawCnt - (decrement << 1))) { return false; } } else { throw new IllegalReferenceCountException(realCnt, -decrement); } Thread.yield(); // this benefits throughput under high contention } }
@Override public ByteBuf content() { if (data.refCnt() <= 0) { throw new IllegalReferenceCountException(data.refCnt()); } return data; }
private ReferenceCounted retain0(int increment) { for (;;) { int refCnt = this.refCnt; final int nextCnt = refCnt + increment; // Ensure we not resurrect (which means the refCnt was 0) and also that we encountered an overflow. if (nextCnt <= increment) { throw new IllegalReferenceCountException(refCnt, increment); } if (refCntUpdater.compareAndSet(this, refCnt, nextCnt)) { break; } } return this; }
private ByteBuf retain0(final int increment) { int oldRef = refCntUpdater.getAndAdd(this, increment); if (oldRef <= 0 || oldRef + increment < oldRef) { // Ensure we don't resurrect (which means the refCnt was 0) and also that we encountered an overflow. refCntUpdater.getAndAdd(this, -increment); throw new IllegalReferenceCountException(oldRef, increment); } return this; }
/** * Like {@link #realRefCnt(int)} but throws if refCnt == 0 */ private static int toLiveRealCnt(int rawCnt, int decrement) { if ((rawCnt & 1) == 0) { return rawCnt >>> 1; } // odd rawCnt => already deallocated throw new IllegalReferenceCountException(0, -decrement); }
@SuppressWarnings("deprecation") private Component newComponent(ByteBuf buf, int offset) { if (checkAccessible && buf.refCnt() == 0) { throw new IllegalReferenceCountException(0); } int srcIndex = buf.readerIndex(), len = buf.readableBytes(); ByteBuf slice = null; if (buf instanceof AbstractUnpooledSlicedByteBuf) { srcIndex += ((AbstractUnpooledSlicedByteBuf) buf).idx(0); slice = buf; buf = buf.unwrap(); } else if (buf instanceof PooledSlicedByteBuf) { srcIndex += ((PooledSlicedByteBuf) buf).adjustment; slice = buf; buf = buf.unwrap(); } return new Component(buf.order(ByteOrder.BIG_ENDIAN), srcIndex, offset, len, slice); }
private boolean retryRelease0(int decrement) { for (;;) { int rawCnt = refCntUpdater.get(this), realCnt = toLiveRealCnt(rawCnt, decrement); if (decrement == realCnt) { if (refCntUpdater.compareAndSet(this, rawCnt, 1)) { deallocate(); return true; } } else if (decrement < realCnt) { // all changes to the raw count are 2x the "real" change if (refCntUpdater.compareAndSet(this, rawCnt, rawCnt - (decrement << 1))) { return false; } } else { throw new IllegalReferenceCountException(realCnt, -decrement); } Thread.yield(); // this benefits throughput under high contention } }
@Override public ByteBuf content() { if (content.refCnt() <= 0) { throw new IllegalReferenceCountException(content.refCnt()); } return content; }