void lock() throws IllegalStateException { while (true) { final boolean success = bytes.tryLockNanosLong(LOCK_OFFSET, lockTimeOutNS); if (success) return; if (currentThread().isInterrupted()) { throw new IllegalStateException( new InterruptedException("Unable to obtain lock, interrupted")); } else { errorListener.onLockTimeout(bytes.threadIdForLockLong(LOCK_OFFSET)); bytes.resetLockInt(LOCK_OFFSET); } } }
public void lock() throws IllegalStateException { while (true) { boolean success = bytes.tryLockNanosInt(LOCK, lockTimeOutNS); if (success) return; if (Thread.currentThread().isInterrupted()) { throw new IllegalStateException( new InterruptedException("Unable to obtain lock, interrupted")); } else { builder.errorListener().onLockTimeout(bytes.threadIdForLockInt(LOCK)); bytes.resetLockInt(LOCK); } } }
Segment(NativeBytes bytes) { this.bytes = bytes; long start = bytes.startAddr() + SharedHashMapBuilder.SEGMENT_HEADER; final NativeBytes iimmapBytes = new NativeBytes(null, start, start + sizeOfMultiMap(), null); iimmapBytes.load(); hashLookup = new IntIntMultiMap(iimmapBytes); start += sizeOfMultiMap(); final NativeBytes bsBytes = new NativeBytes(tmpBytes.bytesMarshallerFactory(), start, start + sizeOfBitSets(), null); freeList = new SingleThreadedDirectBitSet(bsBytes); start += numberOfBitSets() * sizeOfBitSets(); entriesOffset = start - bytes.startAddr(); assert bytes.capacity() >= entriesOffset + entriesPerSegment * entrySize; }
void unlock() { try { bytes.unlockLong(LOCK_OFFSET); } catch (IllegalMonitorStateException e) { errorListener.errorOnUnlock(e); } }
public void unlock() { try { bytes.unlockInt(LOCK); } catch (IllegalMonitorStateException e) { builder.errorListener().errorOnUnlock(e); } }
public Segment(NativeBytes bytes) { this.bytes = bytes; long start = bytes.startAddr() + SharedHashMapBuilder.SEGMENT_HEADER; long size = Maths.nextPower2(builder.entriesPerSegment() * 12, 16 * 8); NativeBytes iimmapBytes = new NativeBytes(tmpBytes.bytesMarshallerFactory(), start, start + size, null); iimmapBytes.load(); hashLookup = new IntIntMultiMap(iimmapBytes); start += size; long bsSize = (builder.entriesPerSegment() + 63) / 64 * 8; NativeBytes bsBytes = new NativeBytes(tmpBytes.bytesMarshallerFactory(), start, start + bsSize, null); // bsBytes.load(); freeList = new SingleThreadedDirectBitSet(bsBytes); start += bsSize * (1 + builder.replicas()); entriesOffset = start - bytes.startAddr(); assert bytes.capacity() >= entriesOffset + builder.entriesPerSegment() * builder.entrySize(); }
@NotNull @Override public BytesStore<Bytes<Underlying>, Underlying> copy() { if (bytesStore.underlyingObject() instanceof ByteBuffer) { ByteBuffer bb = ByteBuffer.allocateDirect(Maths.toInt32(readRemaining())); ByteBuffer bbu = (ByteBuffer) bytesStore.underlyingObject(); ByteBuffer slice = bbu.slice(); slice.position((int) readPosition()); slice.limit((int) readLimit()); bb.put(slice); bb.clear(); return (BytesStore) BytesStore.wrap(bb); } else { return (BytesStore) NativeBytes.copyOf(this); } }
/** * Allocate an elastic buffer with initially no size. * * @return Bytes for writing. */ static NativeBytes<Void> allocateElasticDirect(long initialCapacity) throws IllegalArgumentException { return NativeBytes.nativeBytes(initialCapacity); }
/** * Allocate an elastic buffer with initially no size. * * @return Bytes for writing. */ static NativeBytes<Void> allocateElasticDirect() { return NativeBytes.nativeBytes(); }