public override long waitFor(long sequence, Sequence cursor, Sequence[] dependents, ISequenceBarrier barrier) { long availableSequence; if ((availableSequence = cursor.get()) < sequence) { lock (_lock) { try { ++numWaiters; while ((availableSequence = cursor.get()) < sequence) { barrier.checkAlert(); Monitor.Wait(_lock); } } finally { --numWaiters; } } } if (0 != dependents.Length) { while ((availableSequence = Util.getMinimumSequence(dependents)) < sequence) { barrier.checkAlert(); } } return availableSequence; }
public bool remove(Sequence sequence) { bool found = false; Sequence[] oldSequences; Sequence[] newSequences; do { oldSequences = sequencesRef.get(); int oldSize = oldSequences.Length; newSequences = new Sequence[oldSize - 1]; int pos = 0; for (int i = 0; i < oldSize; i++) { Sequence testSequence = oldSequences[i]; if (sequence == testSequence && !found) { found = true; } else { newSequences[pos++] = testSequence; } } if (!found) { break; } } while (!sequencesRef.compareAndSet(oldSequences, newSequences)); return found; }
public override long incrementAndGet(int delta, Sequence[] dependentSequences) { long nextSequence = claimSequence.addAndGet(delta); waitForFreeSlotAt(nextSequence, dependentSequences, minGatingSequenceThreadLocal.get()); return nextSequence; }
public ProcessingSequenceBarrier(WaitStrategy waitStrategy, Sequence cursorSequence, Sequence[] dependentSequences) { this.waitStrategy = waitStrategy; this.cursorSequence = cursorSequence; this.dependentSequences = dependentSequences; }
public override long incrementAndGet(Sequence[] dependentSequences) { MutableLong minGatingSequence = minGatingSequenceThreadLocal.get(); waitForCapacity(dependentSequences, minGatingSequence); long nextSequence = claimSequence.incrementAndGet(); waitForFreeSlotAt(nextSequence, dependentSequences, minGatingSequence); return nextSequence; }
public void add(Sequence sequence) { Sequence[] oldSequences; Sequence[] newSequences; do { oldSequences = sequencesRef.get(); int oldSize = oldSequences.Length; newSequences = new Sequence[oldSize + 1]; Array.Copy(oldSequences, 0, newSequences, 0, oldSize); newSequences[oldSize] = sequence; } while (!sequencesRef.compareAndSet(oldSequences, newSequences)); }
public override bool hasAvailableCapacity(Sequence[] dependentSequences) { MutableLong minGatingSequence = minGatingSequenceThreadLocal.get(); long wrapPoint = (claimSequence.get() + 1L) - bufferSize; if (wrapPoint > minGatingSequence.get()) { long minSequence = Util.getMinimumSequence(dependentSequences); minGatingSequence.set(minSequence); if (wrapPoint > minSequence) { return false; } } return true; }
public override void serialisePublishing(long sequence, Sequence cursor, int batchSize) { long expectedSequence = sequence - batchSize; if (expectedSequence == cursor.get()) { cursor.set(sequence); if (sequence == claimSequence.get()) { return; } } else { for (long i = expectedSequence + 1; i < sequence; i++) { pendingPublications.lazySet((int)i & indexMask, i); } pendingPublications.set((int)sequence & indexMask, sequence); } if (csLock.compareAndSet(0L, 1L)) { long initialCursor = cursor.get(); long currentCursor = initialCursor; while (currentCursor < claimSequence.get()) { long nextSequence = currentCursor + 1L; if (nextSequence != pendingPublications.get((int)nextSequence & indexMask)) { break; } currentCursor = nextSequence; } if (currentCursor > initialCursor) { cursor.set(currentCursor); } csLock.set(0L); } }
public abstract long waitFor(long sequence, Sequence cursor, Sequence[] dependents, ISequenceBarrier barrier, TimeSpan timeout);
public abstract long waitFor(long sequence, Sequence cursor, Sequence[] dependents, ISequenceBarrier barrier);
private void waitForFreeSlotAt(long sequence, Sequence[] dependentSequences, MutableLong minGatingSequence) { long wrapPoint = sequence - bufferSize; if (wrapPoint > minGatingSequence.get()) { long minSequence; while (wrapPoint > (minSequence = Util.getMinimumSequence(dependentSequences))) { LockSupport.parkNanos(1000L); } minGatingSequence.set(minSequence); } }
private void waitForCapacity(Sequence[] dependentSequences, MutableLong minGatingSequence) { long wrapPoint = (claimSequence.get() + 1L) - bufferSize; if (wrapPoint > minGatingSequence.get()) { long minSequence; while (wrapPoint > (minSequence = Util.getMinimumSequence(dependentSequences))) { LockSupport.parkNanos(1000L); } minGatingSequence.set(minSequence); } }
public override void setSequence(long sequence, Sequence[] dependentSequences) { claimSequence.lazySet(sequence); waitForFreeSlotAt(sequence, dependentSequences, minGatingSequenceThreadLocal.get()); }