public static long append(final VanillaMappedBytes bytes, final long indexValue, final boolean synchronous) { // Position can be changed by another thread, so take a snapshot each loop so that // buffer overflows are not generated when advancing to the next position. // As a result, the position could step backwards when this method is called concurrently, // but the compareAndSwapLong call ensures that data is never overwritten. if(bytes != null) { boolean endOfFile = false; while (!endOfFile) { final long position = bytes.position(); endOfFile = (bytes.limit() - position) < 8; if (!endOfFile) { if (bytes.compareAndSwapLong(position, 0L, indexValue)) { if (synchronous) { bytes.force(); } return position; } bytes.position(position + 8); } } } return -1; }
public static long append(final VanillaMappedBytes bytes, final long indexValue, final boolean synchronous) { // Position can be changed by another thread, so take a snapshot each loop // so that buffer overflows are not generated when advancing to the next // position. As a result, the position could step backwards when this method // is called concurrently, but the compareAndSwapLong call ensures that // data is never overwritten. if (bytes != null) { boolean endOfFile = false; long position = bytes.position(); while (!endOfFile) { endOfFile = (bytes.limit() - position) < 8; if (!endOfFile) { if (bytes.compareAndSwapLong(position, 0L, indexValue)) { bytes.lazyPosition(position + 8); if (synchronous) { bytes.force(); } return position; } } position += 8; } } return -1; }