@Override public boolean compareAndSwapValue(int expected, int value) { return bytes.compareAndSwapInt(offset, expected, value); } }
@Override public boolean compareAndSwapInt(B handle, long offset, int expected, int value) { return handle.compareAndSwapInt(offset, expected, value); }
@Override public boolean compareAndSwapInt(B handle, long offset, int expected, int value) { return handle.compareAndSwapInt(offset, expected, value); }
@Override public boolean compareAndSwapInt(long offset, int expected, int value) throws BufferOverflowException { writeCheckOffset(offset, 4); return bytesStore.compareAndSwapInt(offset, expected, value); }
private long withLock(@NotNull LongSupplier call) throws IllegalStateException, BufferUnderflowException { long valueOffset = offset + LOCKED; int value = bytes.readVolatileInt(valueOffset); if (value != FALSE && value != TRUE) throw new IllegalStateException("Not a lock value"); try { while (true) { if (bytes.compareAndSwapInt(valueOffset, FALSE, TRUE)) { long t = call.getAsLong(); bytes.writeOrderedInt(valueOffset, FALSE); return t; } } } catch (BufferOverflowException e) { throw new AssertionError(e); } }
private int withLock(@NotNull IntSupplier call) throws BufferUnderflowException { long alignedOffset = roundUpTo8ByteAlign(offset); long lockValueOffset = alignedOffset + LOCKED; int lockValue = bytes.readVolatileInt(lockValueOffset); if (lockValue != FALSE && lockValue != TRUE) throw new IllegalStateException(); try { while (true) { if (bytes.compareAndSwapInt(lockValueOffset, FALSE, TRUE)) { int t = call.getAsInt(); bytes.writeOrderedInt(lockValueOffset, FALSE); return t; } } } catch (BufferOverflowException e) { throw new AssertionError(e); } }
@Override public boolean compareAndSet(long index, long expected, long value) { if (!bytes.compareAndSwapInt(LOCK_OFFSET + offset, FALS, TRU)) return false; boolean ret = false; try { if (getVolatileValueAt(index) == expected) { setOrderedValueAt(index, value); ret = true; } return ret; } finally { bytes.writeInt(LOCK_OFFSET + offset, FALS); } }
@Override public void setMaxUsed(long usedAtLeast) { while (true) { if (!bytes.compareAndSwapInt(LOCK_OFFSET + offset, FALS, TRU)) continue; try { if (getUsed() < usedAtLeast) { setUsed(usedAtLeast); } return; } finally { bytes.writeInt(LOCK_OFFSET + offset, FALS); } } }