Beispiel #1
0
            public WaitForResult WaitFor <T>(IBatchConsumer[] consumers, ISequencable ringBuffer, IConsumerBarrier <T> barrier, long sequence)
            {
                var availableSequence = ringBuffer.Cursor; // volatile read

                if (availableSequence < sequence)
                {
                    lock (_gate)
                    {
                        while ((availableSequence = ringBuffer.Cursor) < sequence) // volatile read
                        {
                            if (barrier.IsAlerted)
                            {
                                return(WaitForResult.AlertedResult);
                            }

                            Monitor.Wait(_gate);
                        }
                    }
                }

                if (0 != consumers.Length)
                {
                    while ((availableSequence = consumers.GetMinimumSequence()) < sequence)
                    {
                        if (barrier.IsAlerted)
                        {
                            return(WaitForResult.AlertedResult);
                        }
                    }
                }

                return(new WaitForResult(availableSequence, false));
            }
Beispiel #2
0
            public WaitForResult WaitFor <T>(IBatchConsumer[] consumers, ISequencable ringBuffer, IConsumerBarrier <T> barrier, long sequence)
            {
                long availableSequence;

                if (0 == consumers.Length)
                {
                    while ((availableSequence = ringBuffer.Cursor) < sequence) // volatile read
                    {
                        if (barrier.IsAlerted)
                        {
                            return(WaitForResult.AlertedResult);
                        }

                        Thread.Yield();
                    }
                }
                else
                {
                    while ((availableSequence = consumers.GetMinimumSequence()) < sequence)
                    {
                        if (barrier.IsAlerted)
                        {
                            return(WaitForResult.AlertedResult);
                        }

                        Thread.Yield();
                    }
                }

                return(new WaitForResult(availableSequence, false));
            }
Beispiel #3
0
 /// <summary>
 /// Construct a <see cref="IBatchConsumer"/> that simply tracks a <see cref="RingBuffer{T}"/>.
 /// </summary>
 /// <param name="ringBuffer"></param>
 public NoOpConsumer(ISequencable ringBuffer)
 {
     _ringBuffer = ringBuffer;
 }