예제 #1
0
        public bool Enqueue(TQueueElement item)
        {
            var r = false;
            var reThrowException = false;

            var enabledCountPerformance = true;

            if (OnGetEnabledCountPerformanceProcessFunc != null)
            {
                enabledCountPerformance = OnGetEnabledCountPerformanceProcessFunc();
            }

            var qpcc = _queuePerformanceCountersContainer;

            PerformanceCountersHelper
            .TryCountPerformance
            (
                () =>
            {
                return(enabledCountPerformance);
            }
                , reThrowException
                , qpcc
                .IncrementCountersBeforeCountPerformanceForEnqueue
                //incrementCountersBeforeCountPerformance
                , null
                , null
                , () =>
            {
                Stopwatch stopwatchEnqueue = null;
                if (_isAttachedPerformanceCounters)
                {
                    _stopwatchsPool.TryGet(out stopwatchEnqueue);
                }
                stopwatchEnqueue.Start();
                var element = Tuple
                              .Create
                              (
                    stopwatchEnqueue
                    , item
                              );
                _queue.Enqueue(element);
                //Thread.Sleep(100);
                r = true;
            }
                , (x, y, z) =>
            {
                qpcc
                .CaughtExceptionsPerformanceCounter
                .Increment();
                if (OnEnqueueProcessCaughtException != null)
                {
                    reThrowException = OnEnqueueProcessCaughtException(this, x, y, z);
                }
                if (!reThrowException)
                {
                    if (OnCaughtException != null)
                    {
                        reThrowException = OnCaughtException(this, x, y, z);
                    }
                }
                return(reThrowException);
            }

            );
            return(r);
        }
        public bool Enqueue(T item)
        {
            var r = false;
            var reThrowException = false;

            var enabledCountPerformance = true;

            if (_onEnabledCountPerformanceProcessFunc != null)
            {
                enabledCountPerformance = _onEnabledCountPerformanceProcessFunc();
            }

            var qpcc = PerformanceCountersContainer;

            PerformanceCountersHelper
            .TryCountPerformance
            (
                () =>
            {
                return(enabledCountPerformance);
            }
                , reThrowException
                , qpcc
                .IncrementCountersBeforeCountPerformanceForEnqueue
                //incrementCountersBeforeCountPerformance
                , null
                , null
                , () =>
            {
                Stopwatch stopwatchEnqueue = null;
                if (_isAttachedPerformanceCounters)
                {
                    _stopwatchsPool.TryGet(out stopwatchEnqueue);
                }
                stopwatchEnqueue.Start();
                var element = Tuple
                              .Create
                              (
                    stopwatchEnqueue
                    , item
                              );
                _queue.Enqueue(element);
                r = true;
            }
                , (x, y, z) =>
            {
                qpcc
                .CaughtExceptionsPerformanceCounter
                .Increment();
                if (OnEnqueueProcessCaughtException != null)
                {
                    reThrowException = OnEnqueueProcessCaughtException(this, x, y, z);
                }
                if (!reThrowException)
                {
                    if (OnCaughtException != null)
                    {
                        reThrowException = OnCaughtException(this, x, y, z);
                    }
                }
                return(reThrowException);
            }
                , (x, y, z, w) =>
            {
                if
                (
                    _waitingDequeueThreadsProcessorsStack != null &&
                    _waitingDequeueThreadsProcessorsStack.Count > 0
                )
                {
                    ThreadProcessor processor = null;
                    if
                    (
                        _waitingDequeueThreadsProcessorsStack
                        .TryPop(out processor)
                    )
                    {
                        processor.Waiter.Set();
                        processor = null;
                        //Console.WriteLine("processor = null; {0}", _waitingDequeueThreadsProcessorsStack.Count);
                    }
                }
            }
            );
            return(r);
        }