Пример #1
0
        /// <summary>Find the next task that should be executed, based on priorities and fairness and the like.</summary>
        /// <param name="targetTask">The found task, or null if none was found.</param>
        /// <param name="queueForTargetTask">
        /// The scheduler associated with the found task.  Due to security checks inside of TPL,
        /// this scheduler needs to be used to execute that task.
        /// </param>
        void FindNextTaskNeedsLock(out Task targetTask, out QueuedTaskSchedulerQueue queueForTargetTask)
        {
            targetTask         = null;
            queueForTargetTask = null;

            // Look through each of our queue groups in sorted order.
            // This ordering is based on the priority of the queues.
            foreach (var queueGroup in _queueGroups)
            {
                QueueGroup queues = queueGroup.Value;

                // Within each group, iterate through the queues in a round-robin
                // fashion.  Every time we iterate again and successfully find a task,
                // we'll start in the next location in the group.
                foreach (int i in queues.CreateSearchOrder())
                {
                    queueForTargetTask = queues[i];
                    Queue <Task> items = queueForTargetTask._workItems;
                    if (items.Count > 0)
                    {
                        targetTask = items.Dequeue();
                        if (queueForTargetTask._disposed && items.Count == 0)
                        {
                            RemoveQueueNeedsLock(queueForTargetTask);
                        }
                        queues.NextQueueIndex = (queues.NextQueueIndex + 1) % queueGroup.Value.Count;
                        return;
                    }
                }
            }
        }
Пример #2
0
 /// <summary>Find the next task that should be executed, based on priorities and fairness and the like.</summary>
 /// <param name="targetTask">The found task, or null if none was found.</param>
 /// <param name="queueForTargetTask">
 /// The scheduler associated with the found task.  Due to security checks inside of TPL,
 /// this scheduler needs to be used to execute that task.
 /// </param>
 private void FindNextTask_NeedsLock(out Task targetTask, out QueuedTaskSchedulerQueue queueForTargetTask)
 {
     targetTask         = null;
     queueForTargetTask = null;
     foreach (KeyValuePair <int, QueueGroup> pair in this._queueGroups)
     {
         QueueGroup group = pair.Value;
         foreach (int num in group.CreateSearchOrder())
         {
             queueForTargetTask = group[num];
             Queue <Task> queue = queueForTargetTask._workItems;
             if (queue.Count > 0)
             {
                 targetTask = queue.Dequeue();
                 if (queueForTargetTask._disposed && (queue.Count == 0))
                 {
                     this.RemoveQueue_NeedsLock(queueForTargetTask);
                 }
                 group.NextQueueIndex = (group.NextQueueIndex + 1) % pair.Value.Count;
                 break;
             }
         }
     }
 }