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