Ejemplo n.º 1
0
        protected virtual void ExclusiveProcessing(bool processActions)
        {
            NullSafeSequencer.PointArg(SeqPointTypeUC.Match, TimerProcessorSequencer.ExclusiveProcessing, processActions);
            TimerProcessorStatus lastStatus;

            using (Lock.Enter())
            {
                ActiveProcessing = true;
                NullSafeSequencer.PointArg(SeqPointTypeUC.Match, TimerProcessorSequencer.BeginActiveProcessing, Status);
            }

            while (true)
            {
                using (Lock.Enter())
                {
                    lastStatus = Status;
                    while (Requests.Count > 0 && WorkingRequests.Count < MaxActiveRequests)
                    {
                        WorkingRequests.Enqueue(Requests.Dequeue());
                    }
                    if (Requests.Count <= 0 && WorkingRequests.Count <= 0)
                    {
                        break;
                    }
                }

                TimerProcessorCallBackRequest.Processing(lastStatus, WorkingRequests, ExpiryItems);
            }

            bool processing = processActions && lastStatus != TimerProcessorStatus.Disposed && ExpiryItems.Any();

            NullSafeSequencer.PointArg(SeqPointTypeUC.Match, TimerProcessorSequencer.ActionsProcessing, processing);

            if (processing)
            {
                NullSafeSequencer.PointArg(SeqPointTypeUC.Notify, TimerProcessorSequencer.ActionsProcessingCount, ExpiryItems.Count);
                ExpiryItems.TryExpire(RealTimeSource.GetUtcNow());
            }

            while (true)
            {
                using (Lock.Enter())
                {
                    lastStatus = Status;
                    while (Requests.Count > 0 && WorkingRequests.Count < MaxActiveRequests)
                    {
                        WorkingRequests.Enqueue(Requests.Dequeue());
                    }
                    if (Requests.Count <= 0 && WorkingRequests.Count <= 0)
                    {
                        break;
                    }
                }

                TimerProcessorCallBackRequest.Processing(lastStatus, WorkingRequests, ExpiryItems);
            }

            using (Lock.Enter())
            {
                ActiveProcessing = false;
                TimerProcessorCallBackRequest.Processing(Status, Requests, ExpiryItems);

                if (Status == TimerProcessorStatus.Operating)
                {
                    bool activate = false;
                    activate |= ExpiryItems.Count > 0;
                    activate |= Requests.Count > 0;
                    TryUpdateTimer(activate);
                }
                else
                {
                    TryUpdateTimer(activate: false);
                    ExpiryItems.CancelAllAndClear();
                    Status = TimerProcessorStatus.Disposed;
                    Ticker.Dispose();
                    DisposedTCS.TrySetResult(null);
                }
                NullSafeSequencer.PointArg(SeqPointTypeUC.Match, TimerProcessorSequencer.EndActiveProcessing, Status);
            }
        }
Ejemplo n.º 2
0
        protected virtual void ExclusiveProcessing(bool processActions)
        {
            NullSafeSequencer.PointArg(SeqPointTypeUC.Match, TickGeneratorSequencer.ExclusiveProcessing, processActions);
            TickGeneratorStatus lastStatus;

            using (Lock.Enter())
            {
                ActiveProcessing = true;
                NullSafeSequencer.PointArg(SeqPointTypeUC.Match, TickGeneratorSequencer.BeginActiveProcessing, Status);
            }

            while (true)
            {
                using (Lock.Enter())
                {
                    lastStatus = Status;
                    while (Requests.Count > 0 && WorkingRequests.Count < MaxActiveRequests)
                    {
                        WorkingRequests.Enqueue(Requests.Dequeue());
                    }
                    if (Requests.Count <= 0 && WorkingRequests.Count <= 0)
                    {
                        break;
                    }
                }

                CallBackRequest.Processing(lastStatus, WorkingRequests, Actions);
            }

            bool processing = processActions && lastStatus != TickGeneratorStatus.Disposed && Actions.Count > 0;

            NullSafeSequencer.PointArg(SeqPointTypeUC.Match, TickGeneratorSequencer.ActionsProcessing, processing);

            if (processing)
            {
                NullSafeSequencer.PointArg(SeqPointTypeUC.Notify, TickGeneratorSequencer.ActionsProcessingCount, Actions.Count);
                foreach (Action action in Actions)
                {
                    action();
                }
            }

            while (true)
            {
                using (Lock.Enter())
                {
                    lastStatus = Status;
                    while (Requests.Count > 0 && WorkingRequests.Count < MaxActiveRequests)
                    {
                        WorkingRequests.Enqueue(Requests.Dequeue());
                    }
                    if (Requests.Count <= 0 && WorkingRequests.Count <= 0)
                    {
                        break;
                    }
                }

                CallBackRequest.Processing(lastStatus, WorkingRequests, Actions);
            }

            using (Lock.Enter())
            {
                ActiveProcessing = false;
                CallBackRequest.Processing(lastStatus, Requests, Actions);

                if (Status == TickGeneratorStatus.Operating)
                {
                    bool activate = false;
                    activate |= Actions.Count > 0;
                    activate |= Requests.Count > 0;
                    TryUpdateTimer(activate);
                }
                else
                {
                    TryUpdateTimer(activate: false);
                    Period = null;
                    Actions.Clear();
                    Status = TickGeneratorStatus.Disposed;
                    DisposedTCS.TrySetResult(null);
                }
                NullSafeSequencer.PointArg(SeqPointTypeUC.Match, TickGeneratorSequencer.EndActiveProcessing, Status);
            }
        }