OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
Sami
2014/10/27 18:56:29
Looks like the selector files got left in this pat
rmcilroy
2014/10/28 18:26:53
Opps, bad upload - Done.
| |
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 // A RendererSchedulerSelector is a TaskQueueSelector which is used by the | |
16 // RendererScheduler to enable prioritization of particular queues depending on | |
17 // circumstances. | |
18 class RendererSchedulerSelector : public TaskQueueSelector { | |
19 public: | |
20 enum QueuePriority { | |
21 // Queues with control priority will run before any other queue, and will | |
22 // explicitly starve other queues. Typically this should only be used for | |
23 // private queues which perform control operations. | |
24 kControlPriority, | |
25 // Queues with high priority will be selected preferentially over normal or | |
26 // best effort queues. The selector will ensure that high priority queues | |
27 // cannot completely starve normal priority queues. | |
28 kHighPriority, | |
29 // Queues with normal priority are the default. | |
30 kNormalPriority, | |
31 // Queues with best effort priority will only be run if all other queues are | |
32 // empty. They can be starved by the other queues. | |
33 kBestEffortPriority, | |
34 // Must be the last entry. | |
35 kQueuePriorityCount, | |
36 kFirstQueuePriority = kControlPriority, | |
37 }; | |
38 | |
39 RendererSchedulerSelector(); | |
40 virtual ~RendererSchedulerSelector(); | |
41 | |
42 // Set the priority of |queue_index| to |set_priority|. | |
43 void SetQueuePriority(size_t queue_index, QueuePriority priority); | |
44 | |
45 // Enable the |queue_index| with a priority of |priority|. By default all | |
46 // queues are enabled with normal priority. | |
47 void EnableQueue(size_t queue_index, QueuePriority priority); | |
48 | |
49 // Disable the |queue_index|. | |
50 void DisableQueue(size_t queue_index); | |
51 | |
52 // TaskQueueSelector implementation: | |
53 virtual void RegisterWorkQueues( | |
54 const std::vector<const base::TaskQueue*>& work_queues) override; | |
55 virtual bool SelectWorkQueueToService(size_t* out_queue_index) override; | |
56 | |
57 private: | |
58 // Returns true if queueA contains an older task than queueB. | |
59 bool IsOlder(const base::TaskQueue* queueA, | |
60 const base::TaskQueue* queueB) const; | |
61 | |
62 // Return true if |out_queue_index| indicates the index of the queue with | |
63 // the oldest pending task from the set of queues of |priority|, or | |
64 // false if all queues of that priority are empty. | |
65 bool ChooseOldestWithPriority(QueuePriority priority, | |
66 size_t* out_queue_index) const; | |
67 | |
68 // Returns true if |queue_index| is enabled with the given |priority|. | |
69 bool QueueEnabledWithPriority(size_t queue_index, | |
70 QueuePriority priority) const; | |
71 | |
72 // Number of high priority tasks which can be run before a normal priority | |
73 // task should be selected to prevent starvation. | |
74 // TODO(rmcilroy): Check if this is a good value. | |
75 static const int kMaxStarvationTasks = 5; | |
76 | |
77 base::ThreadChecker main_thread_checker_; | |
78 std::vector<const base::TaskQueue*> work_queues_; | |
79 std::set<size_t> queue_priorities_[kQueuePriorityCount]; | |
80 int normal_queue_starvation_count_; | |
81 }; | |
82 | |
83 } // namespace content | |
84 | |
85 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLICY_H_ | |
OLD | NEW |