/// <summary>
        /// Wait for the <see cref="RingBuffer"/> to drain of published events then halt the workers.
        /// </summary>
        public void drainAndHalt()
        {
            var workerSequences = getWorkerSequences();

            while (ringBuffer.GetCursor > Util.GetMinimumSequence(workerSequences))
            {
                Thread.Sleep(0);
            }

            foreach (WorkProcessor <T> processor in workProcessors)
            {
                processor.Halt();
            }

            started.WriteFullFence(false);
        }
Exemple #2
0
        public long WaitFor(long sequence, Sequence cursor, Sequence dependentSequence, ISequenceBarrier barrier)
        {
            long availableSequence;

            if ((availableSequence = dependentSequence.Value) < sequence)
            {
                bool lockToken = false;
                Monitor.Enter(obj, ref lockToken);
                try
                {
                    do
                    {
                        signalNeeded.WriteFullFence(true);

                        if ((availableSequence = dependentSequence.Value) >= sequence)
                        {
                            break;
                        }

                        barrier.CheckAlert();
                        Monitor.Wait(obj);
                    }while ((availableSequence = dependentSequence.Value) < sequence);
                }
                finally
                {
                    if (lockToken)
                    {
                        Monitor.Exit(obj);
                    }
                }
            }

            while ((availableSequence = dependentSequence.Value) < sequence)
            {
                barrier.CheckAlert();
            }

            return(availableSequence);
        }
 public void Halt()
 {
     running.WriteFullFence(false);
     sequenceBarrier.Alert();
 }
 public void Halt()
 {
     running.WriteFullFence(false);
 }
 public void WriteFullFenceChangesInitialValue()
 {
     _volatile.WriteFullFence(NewValue);
     Assert.AreEqual(NewValue, _volatile.ReadUnfenced());
 }