示例#1
0
        public long WaitFor(IConsumer[] consumers, IRingBuffer <T> ringBuffer, IConsumerBarrier <T> barrier, long sequence)
        {
            long availableSequence;

            if (0 == consumers.Length)
            {
                while ((availableSequence = ringBuffer.Cursor) < sequence)
                {
                    if (barrier.IsAlerted())
                    {
                        throw AlertException.ALERT_EXCEPTION;
                    }
                }
            }
            else
            {
                while ((availableSequence = Util.GetMinimumSequence(consumers)) < sequence)
                {
                    if (barrier.IsAlerted())
                    {
                        throw AlertException.ALERT_EXCEPTION;
                    }
                }
            }

            return(availableSequence);
        }
示例#2
0
        public long WaitFor(IConsumer[] consumers, IRingBuffer <T> ringBuffer, IConsumerBarrier <T> barrier,
                            long sequence, long timeout)
        {
            long availableSequence;

            if ((availableSequence = ringBuffer.Cursor) < sequence)
            {
                lock (_lock)
                {
                    try
                    {
                        while ((availableSequence = ringBuffer.Cursor) < sequence)
                        {
                            if (barrier.IsAlerted())
                            {
                                throw AlertException.ALERT_EXCEPTION;
                            }

                            if (!_waithandle.WaitOne((int)timeout))
                            {
                                break;
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }

            if (0 != consumers.Length)
            {
                while ((availableSequence = Util.GetMinimumSequence(consumers)) < sequence)
                {
                    if (barrier.IsAlerted())
                    {
                        throw AlertException.ALERT_EXCEPTION;
                    }
                }
            }

            return(availableSequence);
        }
示例#3
0
        public long WaitFor(IConsumer[] consumers, IRingBuffer <T> ringBuffer, IConsumerBarrier <T> barrier,
                            long sequence, long timeout)
        {
            long currentTime = _timer.ElapsedMilliseconds;
            long cutoff      = currentTime + timeout;
            long availableSequence;

            if (0 == consumers.Length)
            {
                while ((availableSequence = ringBuffer.Cursor) < sequence)
                {
                    if (barrier.IsAlerted())
                    {
                        throw AlertException.ALERT_EXCEPTION;
                    }

                    ThreadYield();
                    if (_timer.ElapsedMilliseconds > cutoff)
                    {
                        break;
                    }
                }
            }
            else
            {
                while ((availableSequence = Util.GetMinimumSequence(consumers)) < sequence)
                {
                    if (barrier.IsAlerted())
                    {
                        throw AlertException.ALERT_EXCEPTION;
                    }

                    ThreadYield();
                    if (_timer.ElapsedMilliseconds > cutoff)
                    {
                        break;
                    }
                }
            }

            return(availableSequence);
        }