Example #1
0
        public List <StubEntry> Call()
        {
            latch.Set();
            consumerBarrier.WaitFor(toWaitForSequence);

            List <StubEntry> retval = new List <StubEntry>();

            for (long l = initialSequence; l <= toWaitForSequence; l++)
            {
                retval.Add(consumerBarrier.GetEntry(l));
            }
            return(retval);
        }
Example #2
0
        /// <summary>
        /// It is ok to have another thread rerun this method after a halt().
        /// </summary>
        public void Run()
        {
            _running.Data = true;

            OnStart();

            var nextSequence = Sequence + 1;

            while (_running.Data)
            {
                var waitForResult = _consumerBarrier.WaitFor(nextSequence);
                if (!waitForResult.IsAlerted)
                {
                    var availableSequence = waitForResult.AvailableSequence;
                    while (nextSequence <= availableSequence)
                    {
                        T data = _consumerBarrier.GetEntry(nextSequence);
                        _handler.OnAvailable(nextSequence, data);

                        nextSequence++;
                    }
                    _handler.OnEndOfBatch();

                    if (_delaySequenceWrite)
                    {
                        if (nextSequence > _nextSequencePublish)
                        {
                            Sequence              = nextSequence - 1; // volatile write
                            _nextSequencePublish += _sequenceUpdatePeriod;
                        }
                    }
                    else
                    {
                        Sequence = nextSequence - 1; // volatile write
                    }
                }
            }

            OnStop();
        }