コード例 #1
0
    /// <summary>
    /// <para>
    /// Polls for events using the given handler.
    /// </para>
    /// <para>
    /// This poller will continue to feed events to the given handler until known available
    /// events are consumed or <see cref="EventPoller.Handler{T}"/> returns false.
    /// </para>
    /// <para>
    /// Note that it is possible for more events to become available while the current events
    /// are being processed. A further call to this method will process such events.
    /// </para>
    /// </summary>
    public EventPoller.PollState Poll(EventPoller.Handler <T> eventHandler)
    {
        var currentSequence   = _sequence.Value;
        var nextSequence      = currentSequence + 1;
        var availableSequence = _sequencer.GetHighestPublishedSequence(nextSequence, _dependentSequences.Value);

        if (nextSequence <= availableSequence)
        {
            var processedSequence = currentSequence;

            try
            {
                bool processNextEvent;
                do
                {
                    var evt = _dataProvider[nextSequence];
                    processNextEvent  = eventHandler(evt, nextSequence, nextSequence == availableSequence);
                    processedSequence = nextSequence;
                    nextSequence++;
                }while (nextSequence <= availableSequence & processNextEvent);
            }
            finally
            {
                _sequence.SetValue(processedSequence);
            }

            return(EventPoller.PollState.Processing);
        }

        if (_sequencer.Cursor >= nextSequence)
        {
            return(EventPoller.PollState.Gating);
        }

        return(EventPoller.PollState.Idle);
    }
コード例 #2
0
 public PollRunnable(EventPoller <PerfEvent> poller)
 {
     _poller       = poller;
     _eventHandler = OnEvent;
 }