OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_SCHEDULER_RENDERER_TASK_QUEUE_SELECTOR_H | 5 #ifndef CONTENT_RENDERER_SCHEDULER_RENDERER_TASK_QUEUE_SELECTOR_H |
6 #define CONTENT_RENDERER_SCHEDULER_RENDERER_TASK_QUEUE_SELECTOR_H | 6 #define CONTENT_RENDERER_SCHEDULER_RENDERER_TASK_QUEUE_SELECTOR_H |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // queues are enabled with normal priority. | 48 // queues are enabled with normal priority. |
49 void EnableQueue(size_t queue_index, QueuePriority priority); | 49 void EnableQueue(size_t queue_index, QueuePriority priority); |
50 | 50 |
51 // Disable the |queue_index|. | 51 // Disable the |queue_index|. |
52 void DisableQueue(size_t queue_index); | 52 void DisableQueue(size_t queue_index); |
53 | 53 |
54 // TaskQueueSelector implementation: | 54 // TaskQueueSelector implementation: |
55 void RegisterWorkQueues( | 55 void RegisterWorkQueues( |
56 const std::vector<const base::TaskQueue*>& work_queues) override; | 56 const std::vector<const base::TaskQueue*>& work_queues) override; |
57 bool SelectWorkQueueToService(size_t* out_queue_index) override; | 57 bool SelectWorkQueueToService(size_t* out_queue_index) override; |
| 58 void AsValueInto(base::debug::TracedValue* state) const override; |
58 | 59 |
59 private: | 60 private: |
60 // Returns true if queueA contains an older task than queueB. | 61 // Returns true if queueA contains an older task than queueB. |
61 static bool IsOlder(const base::TaskQueue* queueA, | 62 static bool IsOlder(const base::TaskQueue* queueA, |
62 const base::TaskQueue* queueB); | 63 const base::TaskQueue* queueB); |
63 | 64 |
64 // Returns the priority which is next after |priority|. | 65 // Returns the priority which is next after |priority|. |
65 static QueuePriority NextPriority(QueuePriority priority); | 66 static QueuePriority NextPriority(QueuePriority priority); |
66 | 67 |
| 68 static const char* PriorityToString(QueuePriority priority); |
| 69 |
67 // Return true if |out_queue_index| indicates the index of the queue with | 70 // Return true if |out_queue_index| indicates the index of the queue with |
68 // the oldest pending task from the set of queues of |priority|, or | 71 // the oldest pending task from the set of queues of |priority|, or |
69 // false if all queues of that priority are empty. | 72 // false if all queues of that priority are empty. |
70 bool ChooseOldestWithPriority(QueuePriority priority, | 73 bool ChooseOldestWithPriority(QueuePriority priority, |
71 size_t* out_queue_index) const; | 74 size_t* out_queue_index) const; |
72 | 75 |
73 // Returns true if |queue_index| is enabled with the given |priority|. | 76 // Returns true if |queue_index| is enabled with the given |priority|. |
74 bool QueueEnabledWithPriority(size_t queue_index, | 77 bool QueueEnabledWithPriority(size_t queue_index, |
75 QueuePriority priority) const; | 78 QueuePriority priority) const; |
76 | 79 |
| 80 // Called whenever the selector chooses a task queue for execution with the |
| 81 // priority |priority|. |
| 82 void DidSelectQueueWithPriority(QueuePriority priority); |
| 83 |
77 // Number of high priority tasks which can be run before a normal priority | 84 // Number of high priority tasks which can be run before a normal priority |
78 // task should be selected to prevent starvation. | 85 // task should be selected to prevent starvation. |
79 // TODO(rmcilroy): Check if this is a good value. | 86 // TODO(rmcilroy): Check if this is a good value. |
80 static const size_t kMaxStarvationTasks = 5; | 87 static const size_t kMaxStarvationTasks = 5; |
81 | 88 |
82 base::ThreadChecker main_thread_checker_; | 89 base::ThreadChecker main_thread_checker_; |
83 std::vector<const base::TaskQueue*> work_queues_; | 90 std::vector<const base::TaskQueue*> work_queues_; |
84 std::set<size_t> queue_priorities_[QUEUE_PRIORITY_COUNT]; | 91 std::set<size_t> queue_priorities_[QUEUE_PRIORITY_COUNT]; |
85 size_t starvation_count_; | 92 size_t starvation_count_; |
86 DISALLOW_COPY_AND_ASSIGN(RendererTaskQueueSelector); | 93 DISALLOW_COPY_AND_ASSIGN(RendererTaskQueueSelector); |
87 }; | 94 }; |
88 | 95 |
89 } // namespace content | 96 } // namespace content |
90 | 97 |
91 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_TASK_QUEUE_SELECTOR_H | 98 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_TASK_QUEUE_SELECTOR_H |
OLD | NEW |