public void exceedsMaximumBufferSize_onRead(ConcurrentLinkedDictionary <int, int> map) { PaddedAtomicLong drainCounter = map.readBufferDrainAtWriteCount[ConcurrentLinkedDictionary <int, int> .readBufferIndex()]; map.readBufferWriteCount[ConcurrentLinkedDictionary <int, int> .readBufferIndex()].SetValue(ConcurrentLinkedDictionary <int, int> .READ_BUFFER_THRESHOLD - 1); map.afterRead(null); Assert.That(drainCounter.GetValue(), Is.EqualTo(0L)); map.afterRead(null); Assert.That(drainCounter.GetValue(), Is.EqualTo(ConcurrentLinkedDictionary <int, int> .READ_BUFFER_THRESHOLD + 1L)); }
public void updateRecency_onGetQuietly(ConcurrentLinkedDictionary <int, int> map) { PaddedAtomicLong drainCounter = map.readBufferDrainAtWriteCount[ConcurrentLinkedDictionary <int, int> .readBufferIndex()]; var first = map.evictionDeque.Peek(); long drained = drainCounter.GetValue(); map.GetQuietly(first.Key); map.DrainBuffers(); Assert.That(map.evictionDeque.Peek(), Is.SameAs(first)); Assert.That(drainCounter.GetValue(), Is.EqualTo(drained)); }
public void drain_onRead(ConcurrentLinkedDictionary <int, int> map) { PaddedAtomicReference <ConcurrentLinkedDictionary <int, int> .Node>[] buffer = map.readBuffers[ConcurrentLinkedDictionary <int, int> .readBufferIndex()]; PaddedAtomicLong writeCounter = map.readBufferWriteCount[ConcurrentLinkedDictionary <int, int> .readBufferIndex()]; for (int i = 0; i < ConcurrentLinkedDictionary <int, int> .READ_BUFFER_THRESHOLD; i++) { var x = map[1]; } int pending = 0; foreach (PaddedAtomicReference <ConcurrentLinkedDictionary <int, int> .Node> slot in buffer) { if (slot.GetValue() != null) { pending++; } } Assert.That(pending, Is.EqualTo(ConcurrentLinkedDictionary <int, int> .READ_BUFFER_THRESHOLD)); Assert.That((int)writeCounter.GetValue(), Is.EqualTo(pending)); var k = map [1]; Assert.That(map.readBufferReadCount[ConcurrentLinkedDictionary <int, int> .readBufferIndex()], Is.EqualTo(writeCounter.GetValue())); for (int i = 0; i < map.readBuffers.Length; i++) { Assert.That(map.readBuffers[ConcurrentLinkedDictionary <int, int> .readBufferIndex()][i].GetValue(), Is.Null); } }
public void Can_be_assigned() { _num.SetValue(10L); PaddedAtomicLong y = _num; y.GetValue().Should().Be(10L); }
public void PaddedAtomicLong_CanBeAssigned() { this.num.SetValue(10L); PaddedAtomicLong y = num; y.GetValue().Should().Be(10L); }
/// <summary> /// Flip a phase in the {@link WriterReaderPhaser} instance, {@link WriterReaderPhaser#flipPhase()} /// can only be called while holding the readerLock(). /// {@link WriterReaderPhaser#flipPhase()} will return only after all writer critical sections (protected by /// {@link WriterReaderPhaser#writerCriticalSectionEnter()} ()} and /// {@link WriterReaderPhaser#writerCriticalSectionExit(long)} ()}) that may have been in flight when the /// {@link WriterReaderPhaser#flipPhase()} call were made had completed. /// No actual writer critical section activity is required for {@link WriterReaderPhaser#flipPhase()} to /// succeed. /// However, {@link WriterReaderPhaser#flipPhase()} is lock-free with respect to calls to /// {@link WriterReaderPhaser#writerCriticalSectionEnter()} and /// {@link WriterReaderPhaser#writerCriticalSectionExit(long)}. It may spin-wait for for active /// writer critical section code to complete. /// </summary> /// <param name="yieldTimeNsec">The amount of time (in nanoseconds) to sleep in each yield if yield loop is needed.</param> public void FlipPhase(long yieldTimeNsec = 0) { if (!Monitor.IsEntered(readerLockObject)) { throw new ThreadStateException("flipPhase() can only be called while holding the readerLock()"); } var nextPhaseIsEven = (startEpoch.GetValue() < 0); // Current phase is odd... long initialStartValue; // First, clear currently unused [next] phase end epoch (to proper initial value for phase): if (nextPhaseIsEven) { initialStartValue = 0; evenEndEpoch.SetValue(initialStartValue); } else { initialStartValue = long.MinValue; oddEndEpoch.SetValue(initialStartValue); } // Next, reset start value, indicating new phase, and retain value at flip: var startValueAtFlip = startEpoch.GetAndSet(initialStartValue); // Now, spin until previous phase end value catches up with start value at flip: bool caughtUp; do { if (nextPhaseIsEven) { caughtUp = (oddEndEpoch.GetValue() == startValueAtFlip); } else { caughtUp = (evenEndEpoch.GetValue() == startValueAtFlip); } if (!caughtUp) { if (yieldTimeNsec == 0) { //TODO: HdrHistogram Task.Yield(); } else { Thread.Sleep(TimeSpan.FromMilliseconds(yieldTimeNsec / 1000000.0)); } } } while (!caughtUp); }
public void Get() { // ReSharper disable UnusedVariable var x = _num.GetValue(); // ReSharper restore UnusedVariable }
public void Can_add_value() { _num.Add(7L).Should().Be(7L); _num.GetValue().Should().Be(7L); }
public void Get() { var x = _num.GetValue(); }