Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_RENDERER_SCHEDULER_RENDERER_TASK_QUEUE_SELECTOR_H | |
| 6 #define CONTENT_RENDERER_SCHEDULER_RENDERER_TASK_QUEUE_SELECTOR_H | |
| 7 | |
| 8 #include <set> | |
| 9 | |
| 10 #include "base/threading/thread_checker.h" | |
| 11 #include "content/renderer/scheduler/task_queue_selector.h" | |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 // A RendererSchedulerSelector is a TaskQueueSelector which is used by the | |
|
no sievers
2014/10/28 17:40:12
nit: RendererSchedulerSelector -> RendererTaskQueu
rmcilroy
2014/10/28 17:48:51
Oops, done, thanks!
| |
| 16 // RendererScheduler to enable prioritization of particular task queues. | |
| 17 class RendererTaskQueueSelector : public TaskQueueSelector { | |
| 18 public: | |
| 19 enum QueuePriority { | |
| 20 // Queues with control priority will run before any other queue, and will | |
| 21 // explicitly starve other queues. Typically this should only be used for | |
| 22 // private queues which perform control operations. | |
| 23 CONTROL_PRIORITY, | |
| 24 // Queues with high priority will be selected preferentially over normal or | |
| 25 // best effort queues. The selector will ensure that high priority queues | |
| 26 // cannot completely starve normal priority queues. | |
| 27 HIGH_PRIORITY, | |
| 28 // Queues with normal priority are the default. | |
| 29 NORMAL_PRIORITY, | |
| 30 // Queues with best effort priority will only be run if all other queues are | |
| 31 // empty. They can be starved by the other queues. | |
| 32 BEST_EFFORT_PRIORITY, | |
| 33 // Must be the last entry. | |
| 34 QUEUE_PRIORITY_COUNT, | |
| 35 FIRST_QUEUE_PRIORITY = CONTROL_PRIORITY, | |
| 36 }; | |
| 37 | |
| 38 RendererTaskQueueSelector(); | |
| 39 ~RendererTaskQueueSelector() override; | |
| 40 | |
| 41 // Set the priority of |queue_index| to |priority|. | |
| 42 void SetQueuePriority(size_t queue_index, QueuePriority priority); | |
| 43 | |
| 44 // Enable the |queue_index| with a priority of |priority|. By default all | |
| 45 // queues are enabled with normal priority. | |
| 46 void EnableQueue(size_t queue_index, QueuePriority priority); | |
| 47 | |
| 48 // Disable the |queue_index|. | |
| 49 void DisableQueue(size_t queue_index); | |
| 50 | |
| 51 // TaskQueueSelector implementation: | |
| 52 void RegisterWorkQueues( | |
| 53 const std::vector<const base::TaskQueue*>& work_queues) override; | |
| 54 bool SelectWorkQueueToService(size_t* out_queue_index) override; | |
| 55 | |
| 56 private: | |
| 57 // Returns true if queueA contains an older task than queueB. | |
| 58 static bool IsOlder(const base::TaskQueue* queueA, | |
| 59 const base::TaskQueue* queueB); | |
| 60 | |
| 61 // Returns the priority which is next after |priority|. | |
| 62 static QueuePriority NextPriority(QueuePriority priority); | |
| 63 | |
| 64 // Return true if |out_queue_index| indicates the index of the queue with | |
| 65 // the oldest pending task from the set of queues of |priority|, or | |
| 66 // false if all queues of that priority are empty. | |
| 67 bool ChooseOldestWithPriority(QueuePriority priority, | |
| 68 size_t* out_queue_index) const; | |
| 69 | |
| 70 // Returns true if |queue_index| is enabled with the given |priority|. | |
| 71 bool QueueEnabledWithPriority(size_t queue_index, | |
| 72 QueuePriority priority) const; | |
| 73 | |
| 74 // Number of high priority tasks which can be run before a normal priority | |
| 75 // task should be selected to prevent starvation. | |
| 76 // TODO(rmcilroy): Check if this is a good value. | |
| 77 static const size_t kMaxStarvationTasks = 5; | |
| 78 | |
| 79 base::ThreadChecker main_thread_checker_; | |
| 80 std::vector<const base::TaskQueue*> work_queues_; | |
| 81 std::set<size_t> queue_priorities_[QUEUE_PRIORITY_COUNT]; | |
| 82 size_t starvation_count_; | |
| 83 DISALLOW_COPY_AND_ASSIGN(RendererTaskQueueSelector); | |
| 84 }; | |
| 85 | |
| 86 } // namespace content | |
| 87 | |
| 88 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_TASK_QUEUE_SELECTOR_H | |
| OLD | NEW |