Index: content/renderer/scheduler/renderer_scheduler_selector.h |
diff --git a/content/renderer/scheduler/renderer_scheduler_selector.h b/content/renderer/scheduler/renderer_scheduler_selector.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..86a1abda44ed53e18676c4bf91fbe16a87c9aaf8 |
--- /dev/null |
+++ b/content/renderer/scheduler/renderer_scheduler_selector.h |
@@ -0,0 +1,68 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLICY_H_ |
+#define CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLICY_H_ |
+ |
+#include "base/task/task_queue_selector.h" |
+#include "base/threading/thread_checker.h" |
+ |
+namespace content { |
+ |
+class RendererSchedulerSelector : public base::TaskQueueSelector { |
+ public: |
+ enum QueuePriority { |
+ kControlPriority, |
Sami
2014/10/22 13:26:06
Maybe mention that this must be the first entry. A
rmcilroy
2014/10/23 14:54:50
Done.
|
+ kHighPriority, |
+ kNormalPriority, |
+ kBestEffortPriority, |
+ // Must be the last entry. |
+ kQueuePriorityCount, |
+ }; |
+ |
+ RendererSchedulerSelector(); |
+ virtual ~RendererSchedulerSelector(); |
+ |
+ // Set the priority of |queue_index| to |set_priority|. |
+ void SetQueuePriority(size_t queue_index, QueuePriority priority); |
+ |
+ // Enable the |queue_index| with a priority of |priority|. By default all |
+ // queues are enabled with normal priority. |
+ void EnableQueue(size_t queue_index, QueuePriority priority); |
+ |
+ // Disable the |queue_index|. |
+ void DisableQueue(size_t queue_index); |
+ |
+ // TaskQueueSelector implementation: |
+ virtual void RegisterWorkQueues( |
+ const std::vector<const base::TaskQueue*>& work_queues) override; |
+ virtual bool SelectWorkQueueToService(size_t* out_queue_index) override; |
+ |
+ private: |
+ // Return true if |out_queue_index| indicates the index of the queue with |
+ // the oldest pending task from the set of queues of |priority|, or |
+ // false if all queues of that priority are empty. |
+ bool ChooseOldestWithPriority(QueuePriority priority, |
+ size_t* out_queue_index) const; |
+ |
+ // Returns true if |queue_index| is enabled with the given |priority|. |
+ bool QueueEnabledWithPriority( |
+ size_t queue_index, QueuePriority priority) const; |
+ |
+ static QueuePriority NextPriority(QueuePriority priority); |
+ size_t PrioritiesMaskFromQueueIndex(size_t queue_index) const; |
+ |
+ // Number of high priority tasks which can be run before a normal priority |
+ // task should be selected to prevent starvation. |
+ static const int kMaxStarvationTasks = 5; |
Sami
2014/10/22 13:26:06
Any science behind this number? :) We should check
rmcilroy
2014/10/23 14:54:50
Yes, no science :). I will run against tough_sche
|
+ |
+ base::ThreadChecker main_thread_checker_; |
+ std::vector<const base::TaskQueue*> work_queues_; |
+ size_t queue_priorities_[kQueuePriorityCount]; |
Sami
2014/10/22 14:49:24
Could you add a comment here that explains the dat
rmcilroy
2014/10/23 14:54:50
Yes makes sense. I'll update this on my next patch
rmcilroy
2014/10/24 14:58:29
Done. Changed it to use a set.
|
+ int normal_queue_starvation_count_; |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLICY_H_ |