Ejemplo n.º 1
0
        private QueueManager()
        {
            _defaultQueues    = new BlockingPriorityQueue <DispatchQueue> (10);
            _highQueues       = new BlockingPriorityQueue <DispatchQueue> (10);
            _lowQueues        = new BlockingPriorityQueue <DispatchQueue> (10);
            _backgroundQueues = new BlockingPriorityQueue <DispatchQueue> (10);

            Thread monitor = new Thread(QueueMonitor);

            monitor.Priority = ThreadPriority.BelowNormal;
            monitor.Start();
        }
Ejemplo n.º 2
0
        private ThreadPriority PriorityForQueue(BlockingPriorityQueue <DispatchQueue> queue)
        {
            if (queue == _defaultQueues)
            {
                return(ThreadPriority.Normal);
            }

            if (queue == _highQueues)
            {
                return(ThreadPriority.Highest);
            }

            if (queue == _lowQueues)
            {
                return(ThreadPriority.Lowest);
            }

            return(ThreadPriority.BelowNormal);
        }
Ejemplo n.º 3
0
 private void CheckPriorityQueue(BlockingPriorityQueue <DispatchQueue> queue)
 {
     while (queue.Count() > MAX_QUEUE_SIZE)
     {
         DispatchQueue dQueue = queue.Dequeue();
         if (dQueue == null)
         {
             return;
         }
         if (dQueue.State == DispatchQueue.QueueState.Idle || dQueue.State == DispatchQueue.QueueState.Disposed)
         {
             dQueue.Dispose();
             Console.WriteLine("Removing queue");
         }
         else
         {
             break;
         }
     }
 }
Ejemplo n.º 4
0
        //private static object _getterLock = new object();
        private DispatchQueue GetDispatchQueue(BlockingPriorityQueue <DispatchQueue> blockerQueue)
        {
            DispatchQueue queue = blockerQueue.Peek();

            if (queue == null || blockerQueue.Count() < MAX_QUEUE_SIZE || (blockerQueue.Count() >= MAX_QUEUE_SIZE && queue.Size() >= MAX_QUEUE_TOLERANCE))
            {
                queue = new DispatchQueue("Concurrent Queue " + blockerQueue.Count(), PriorityForQueue(blockerQueue));
            }
            else
            {
                queue = blockerQueue.Dequeue();
            }
            Console.WriteLine("Queue has " + queue.Size() + " jobs");
            Console.WriteLine(blockerQueue.Count() + " Queues");
            blockerQueue.enqueue(queue);

            lock (_monitorLock)
            {
                Monitor.Pulse(_monitorLock);
            }
            return(queue);
        }