Chromium Code Reviews| 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..40193db6e361a703237afdd7d5e2751bed4e3ad1 |
| --- /dev/null |
| +++ b/content/renderer/scheduler/renderer_scheduler_selector.h |
| @@ -0,0 +1,85 @@ |
| +// 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 <set> |
| + |
| +#include "base/threading/thread_checker.h" |
| +#include "content/renderer/scheduler/task_queue_selector.h" |
| + |
| +namespace content { |
| + |
| +// A RendererSchedulerSelector is a TaskQueueSelector which is used by the |
| +// RendererScheduler to enable prioritization of particular queues depending on |
| +// circumstances. |
| +class RendererSchedulerSelector : public TaskQueueSelector { |
| + public: |
| + enum QueuePriority { |
| + // Queues with control priority will run before any other queue, and will |
| + // explicitly starve other queues. Typically this should only be used for |
| + // private queues which perform control operations. |
| + kControlPriority, |
| + // Queues with high priority will be selected preferentially over normal or |
| + // best effort queues. The selector will ensure that high priority queues |
| + // cannot completely starve normal priority queues. |
| + kHighPriority, |
| + // Queues with normal priority are the default. |
| + kNormalPriority, |
| + // Queues with best effort priority will only be run if all other queues are |
| + // empty. They can be starved by the other queues. |
| + kBestEffortPriority, |
| + // Must be the last entry. |
| + kQueuePriorityCount, |
| + kFirstQueuePriority = kControlPriority, |
|
alexclarke
2014/10/27 10:40:51
Is this used anymore? I had a look in https://cod
rmcilroy
2014/10/27 13:08:05
It's now used in RendererSchedulerSelector::NextPr
|
| + }; |
| + |
| + RendererSchedulerSelector(); |
| + virtual ~RendererSchedulerSelector(); |
| + |
| + // Set the priority of |queue_index| to |set_priority|. |
|
Sami
2014/10/27 11:23:02
s/set_priority/priority/
rmcilroy
2014/10/27 13:08:05
Done.
|
| + 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( |
|
alexclarke
2014/10/27 10:40:51
nit: the style guide says "For clarity, use exactl
rmcilroy
2014/10/27 13:08:05
Done.
|
| + const std::vector<const base::TaskQueue*>& work_queues) override; |
| + virtual bool SelectWorkQueueToService(size_t* out_queue_index) override; |
| + |
| + private: |
| + // Returns true if queueA contains an older task than queueB. |
| + bool IsOlder(const base::TaskQueue* queueA, |
|
alexclarke
2014/10/27 10:40:51
While I think you have reasonable test coverage, I
Sami
2014/10/27 11:23:02
nit: could be static.
rmcilroy
2014/10/27 13:08:05
I'd prefer not to test the internals like these -
rmcilroy
2014/10/27 13:08:05
Done.
|
| + const base::TaskQueue* queueB) const; |
| + |
| + // 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; |
| + |
| + // Number of high priority tasks which can be run before a normal priority |
| + // task should be selected to prevent starvation. |
| + // TODO(rmcilroy): Check if this is a good value. |
| + static const int kMaxStarvationTasks = 5; |
| + |
| + base::ThreadChecker main_thread_checker_; |
| + std::vector<const base::TaskQueue*> work_queues_; |
| + std::set<size_t> queue_priorities_[kQueuePriorityCount]; |
| + int normal_queue_starvation_count_; |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLICY_H_ |