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_SCHEDULER_POLICY_H_ | |
6 #define CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLICY_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 class RendererSchedulerSelector : public TaskQueueSelector { | |
16 public: | |
17 enum QueuePriority { | |
18 kControlPriority, | |
19 kHighPriority, | |
20 kNormalPriority, | |
21 kBestEffortPriority, | |
alexclarke
2014/10/24 15:56:30
Please document what kBestEffortPriority does (i.e
rmcilroy
2014/10/27 16:25:01
Added documentation for all priorities (in other C
| |
22 // Must be the last entry. | |
23 kQueuePriorityCount, | |
24 kFirstQueuePriority = kControlPriority, | |
25 }; | |
26 | |
27 RendererSchedulerSelector(); | |
28 virtual ~RendererSchedulerSelector(); | |
29 | |
30 // Set the priority of |queue_index| to |set_priority|. | |
31 void SetQueuePriority(size_t queue_index, QueuePriority priority); | |
32 | |
33 // Enable the |queue_index| with a priority of |priority|. By default all | |
34 // queues are enabled with normal priority. | |
35 void EnableQueue(size_t queue_index, QueuePriority priority); | |
36 | |
37 // Disable the |queue_index|. | |
38 void DisableQueue(size_t queue_index); | |
39 | |
40 // TaskQueueSelector implementation: | |
41 virtual void RegisterWorkQueues( | |
42 const std::vector<const base::TaskQueue*>& work_queues) override; | |
43 virtual bool SelectWorkQueueToService(size_t* out_queue_index) override; | |
44 | |
45 private: | |
46 // Returns true if queueA contains an older task than queueB. | |
47 bool IsOlder(const base::TaskQueue* queueA, | |
48 const base::TaskQueue* queueB) const; | |
49 | |
50 // Return true if |out_queue_index| indicates the index of the queue with | |
51 // the oldest pending task from the set of queues of |priority|, or | |
52 // false if all queues of that priority are empty. | |
53 bool ChooseOldestWithPriority(QueuePriority priority, | |
54 size_t* out_queue_index) const; | |
55 | |
56 // Returns true if |queue_index| is enabled with the given |priority|. | |
57 bool QueueEnabledWithPriority(size_t queue_index, | |
58 QueuePriority priority) const; | |
59 | |
60 // Number of high priority tasks which can be run before a normal priority | |
61 // task should be selected to prevent starvation. | |
62 // TODO(rmcilroy): Check if this is a good value. | |
63 static const int kMaxStarvationTasks = 5; | |
64 | |
65 base::ThreadChecker main_thread_checker_; | |
66 std::vector<const base::TaskQueue*> work_queues_; | |
67 std::set<size_t> queue_priorities_[kQueuePriorityCount]; | |
68 int normal_queue_starvation_count_; | |
69 }; | |
70 | |
71 } // namespace content | |
72 | |
73 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLICY_H_ | |
OLD | NEW |