/** * Issues (seals) the barrier, meaning no new operations may be issued against it, and expires the current * Group. Must be called before await() for isAfter() to be properly synchronised. */ public void issue() { if (orderOnOrBefore != null) throw new IllegalStateException("Can only call issue() once on each Barrier"); final Group current; synchronized (OpOrder.this) { current = OpOrder.this.current; orderOnOrBefore = current; OpOrder.this.current = current.next = new Group(current); } current.expire(); }
/** * To be called exactly once for each register() call this object is returned for, indicating the operation * is complete */ public void close() { while (true) { int current = running; if (current < 0) { if (runningUpdater.compareAndSet(this, current, current + 1)) { if (current + 1 == FINISHED) { // if we're now finished, unlink ourselves unlink(); } return; } } else if (runningUpdater.compareAndSet(this, current, current - 1)) { return; } } }
/** * Allocate space in this buffer for the provided mutation, and return the allocated Allocation object. * Returns null if there is not enough space in this segment, and a new segment is needed. */ @SuppressWarnings("resource") //we pass the op order around Allocation allocate(Mutation mutation, int size) { final OpOrder.Group opGroup = appendOrder.start(); try { int position = allocate(size); if (position < 0) { opGroup.close(); return null; } markDirty(mutation, position); return new Allocation(this, opGroup, position, (ByteBuffer) buffer.duplicate().position(position).limit(position + size)); } catch (Throwable t) { opGroup.close(); throw t; } }
baseOp.close();
/** * To be called exactly once for each register() call this object is returned for, indicating the operation * is complete */ public void close() { while (true) { int current = running; if (current < 0) { if (runningUpdater.compareAndSet(this, current, current + 1)) { if (current + 1 == FINISHED) { // if we're now finished, unlink ourselves unlink(); } return; } } else if (runningUpdater.compareAndSet(this, current, current - 1)) { return; } } }
/** * To be called exactly once for each register() call this object is returned for, indicating the operation * is complete */ public void close() { while (true) { int current = running; if (current < 0) { if (runningUpdater.compareAndSet(this, current, current + 1)) { if (current + 1 == FINISHED) { // if we're now finished, unlink ourselves unlink(); } return; } } else if (runningUpdater.compareAndSet(this, current, current - 1)) { return; } } }
/** * To be called exactly once for each register() call this object is returned for, indicating the operation * is complete */ public void close() { while (true) { int current = running; if (current < 0) { if (runningUpdater.compareAndSet(this, current, current + 1)) { if (current + 1 == FINISHED) { // if we're now finished, unlink ourselves unlink(); } return; } } else if (runningUpdater.compareAndSet(this, current, current - 1)) { return; } } }
public void allocate(long size, OpOrder.Group opGroup) { assert size >= 0; while (true) { if (parent.tryAllocate(size)) { acquired(size); return; } WaitQueue.Signal signal = opGroup.isBlockingSignal(parent.hasRoom().register()); boolean allocated = parent.tryAllocate(size); if (allocated || opGroup.isBlocking()) { signal.cancel(); if (allocated) // if we allocated, take ownership acquired(size); else // otherwise we're blocking so we're permitted to overshoot our constraints, to just allocate without blocking allocated(size); return; } else signal.awaitUninterruptibly(); } }
public void allocate(long size, OpOrder.Group opGroup) { assert size >= 0; while (true) { if (parent.tryAllocate(size)) { acquired(size); return; } WaitQueue.Signal signal = opGroup.isBlockingSignal(parent.hasRoom().register(parent.blockedTimerContext())); boolean allocated = parent.tryAllocate(size); if (allocated || opGroup.isBlocking()) { signal.cancel(); if (allocated) // if we allocated, take ownership acquired(size); else // otherwise we're blocking so we're permitted to overshoot our constraints, to just allocate without blocking allocated(size); return; } else signal.awaitUninterruptibly(); } }
/** * Allocate space in this buffer for the provided mutation, and return the allocated Allocation object. * Returns null if there is not enough space in this segment, and a new segment is needed. */ @SuppressWarnings("resource") //we pass the op order around Allocation allocate(Mutation mutation, int size) { final OpOrder.Group opGroup = appendOrder.start(); try { int position = allocate(size); if (position < 0) { opGroup.close(); return null; } markDirty(mutation, position); return new Allocation(this, opGroup, position, (ByteBuffer) buffer.duplicate().position(position).limit(position + size)); } catch (Throwable t) { opGroup.close(); throw t; } }
public void allocate(long size, OpOrder.Group opGroup) { assert size >= 0; while (true) { if (parent.tryAllocate(size)) { acquired(size); return; } WaitQueue.Signal signal = opGroup.isBlockingSignal(parent.hasRoom().register(parent.blockedTimerContext())); boolean allocated = parent.tryAllocate(size); if (allocated || opGroup.isBlocking()) { signal.cancel(); if (allocated) // if we allocated, take ownership acquired(size); else // otherwise we're blocking so we're permitted to overshoot our constraints, to just allocate without blocking allocated(size); return; } else signal.awaitUninterruptibly(); } }
/** * To be called exactly once for each register() call this object is returned for, indicating the operation * is complete */ public void close() { while (true) { int current = running; if (current < 0) { if (runningUpdater.compareAndSet(this, current, current + 1)) { if (current + 1 == FINISHED) { // if we're now finished, unlink ourselves unlink(); } return; } } else if (runningUpdater.compareAndSet(this, current, current - 1)) { return; } } }
public void allocate(long size, OpOrder.Group opGroup) { assert size >= 0; while (true) { if (parent.tryAllocate(size)) { acquired(size); return; } WaitQueue.Signal signal = opGroup.isBlockingSignal(parent.hasRoom().register(parent.blockedTimerContext())); boolean allocated = parent.tryAllocate(size); if (allocated || opGroup.isBlocking()) { signal.cancel(); if (allocated) // if we allocated, take ownership acquired(size); else // otherwise we're blocking so we're permitted to overshoot our constraints, to just allocate without blocking allocated(size); return; } else signal.awaitUninterruptibly(); } }
/** * Allocate space in this buffer for the provided mutation, and return the allocated Allocation object. * Returns null if there is not enough space in this segment, and a new segment is needed. */ Allocation allocate(Mutation mutation, int size) { final OpOrder.Group opGroup = appendOrder.start(); try { int position = allocate(size); if (position < 0) { opGroup.close(); return null; } markDirty(mutation, position); return new Allocation(this, opGroup, position, (ByteBuffer) buffer.duplicate().position(position).limit(position + size)); } catch (Throwable t) { opGroup.close(); throw t; } }
@SuppressWarnings("resource") Allocation allocate(int hintSize) { int totalSize = hintSize + ENTRY_OVERHEAD_SIZE; if (totalSize > slab.capacity() / 2) { throw new IllegalArgumentException(String.format("Hint of %s bytes is too large - the maximum size is %s", hintSize, slab.capacity() / 2)); } OpOrder.Group opGroup = appendOrder.start(); // will eventually be closed by the receiver of the allocation try { return allocate(totalSize, opGroup); } catch (Throwable t) { opGroup.close(); throw t; } }
/** * Allocate space in this buffer for the provided mutation, and return the allocated Allocation object. * Returns null if there is not enough space in this segment, and a new segment is needed. */ @SuppressWarnings("resource") //we pass the op order around Allocation allocate(Mutation mutation, int size) { final OpOrder.Group opGroup = appendOrder.start(); try { int position = allocate(size); if (position < 0) { opGroup.close(); return null; } markDirty(mutation, position); return new Allocation(this, opGroup, position, (ByteBuffer) buffer.duplicate().position(position).limit(position + size)); } catch (Throwable t) { opGroup.close(); throw t; } }
public void allocate(long size, OpOrder.Group opGroup) { assert size >= 0; while (true) { if (parent.tryAllocate(size)) { acquired(size); return; } WaitQueue.Signal signal = opGroup.isBlockingSignal(parent.hasRoom().register(parent.blockedTimerContext())); boolean allocated = parent.tryAllocate(size); if (allocated || opGroup.isBlocking()) { signal.cancel(); if (allocated) // if we allocated, take ownership acquired(size); else // otherwise we're blocking so we're permitted to overshoot our constraints, to just allocate without blocking allocated(size); return; } else signal.awaitUninterruptibly(); } }