public static AtomicBoolean FromValue(bool value) { AtomicBoolean temp = new AtomicBoolean(); temp.Value = value; return temp; }
protected virtual void Dispose (bool disposing) { if (disposing){ if (cntd != null){ cntd.Dispose (); cntd = null; } cleaned = null; postPhaseAction = null; } }
public bool Equals (AtomicBoolean rhs) { return this.flag == rhs.flag; }
void InitCountdownEvent () { cleaned = new AtomicBoolean (); cntd = new CountdownEvent (participants); }
void PostPhaseAction (AtomicBoolean cl) { if (postPhaseAction != null) postPhaseAction (this); InitCountdownEvent (); cl.Value = true; phase++; }
bool Wait (Func<CountdownEvent, bool> associate, CountdownEvent temp, AtomicBoolean cl) { if (!associate (temp)) return false; SpinWait sw = new SpinWait (); while (!cl.Value) sw.SpinOnce (); return true; }
public void shouldPreventPublishersOvertakingEventProcessorWrapPoint() { int ringBufferSize = 4; CountDownLatch latch = new CountDownLatch(ringBufferSize); AtomicBoolean publisherComplete = new AtomicBoolean(false); RingBuffer<StubEvent> ringBuffer = new RingBuffer<StubEvent>(StubEvent.EVENT_FACTORY, ringBufferSize); TestEventProcessor processor = new TestEventProcessor(ringBuffer.newBarrier()); ringBuffer.setGatingSequences(processor.getSequence()); Thread thread = new Thread(() => { { for (int i = 0; i <= ringBufferSize; i++) { long sequence = ringBuffer.next(); StubEvent @event = ringBuffer.get(sequence); @event.setValue(i); ringBuffer.publish(sequence); latch.countDown(); } publisherComplete.set(true); } }); thread.Start(); latch.await(); assertEquals(ringBuffer.getCursor(), ringBufferSize - 1); Assert.IsFalse(publisherComplete.get()); processor.run(); thread.Join(); Assert.IsTrue(publisherComplete.get()); }
bool Wait (Func<CountdownEvent, bool> associate, CountdownEvent temp, AtomicBoolean cl) { if (!associate (temp)) return false; SpinWait sw = new SpinWait (); while (!cl.Value) { //Console.WriteLine (cleaned); sw.SpinOnce (); } return true; }