| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_SELECTOR_H_ | 5 #ifndef COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_SELECTOR_H_ |
| 6 #define COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_SELECTOR_H_ | 6 #define COMPONENTS_SCHEDULER_BASE_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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 return &immediate_work_queue_sets_; | 65 return &immediate_work_queue_sets_; |
| 66 } | 66 } |
| 67 | 67 |
| 68 // Returns true if all the enabled work queues are empty. Returns false | 68 // Returns true if all the enabled work queues are empty. Returns false |
| 69 // otherwise. | 69 // otherwise. |
| 70 bool EnabledWorkQueuesEmpty() const; | 70 bool EnabledWorkQueuesEmpty() const; |
| 71 | 71 |
| 72 protected: | 72 protected: |
| 73 // Return true if |out_queue| contains the queue with the oldest pending task | 73 // Return true if |out_queue| contains the queue with the oldest pending task |
| 74 // from the set of queues of |priority|, or false if all queues of that | 74 // from the set of queues of |priority|, or false if all queues of that |
| 75 // priority are empty. | 75 // priority are empty. In addition |out_chose_delayed_over_immediate| is set |
| 76 // to true iff we chose a delayed work queue in favour of an immediate work |
| 77 // queue. This method will force select an immediate task if those are being |
| 78 // starved by delayed tasks. |
| 76 bool ChooseOldestWithPriority(TaskQueue::QueuePriority priority, | 79 bool ChooseOldestWithPriority(TaskQueue::QueuePriority priority, |
| 80 bool* out_chose_delayed_over_immediate, |
| 77 WorkQueue** out_work_queue) const; | 81 WorkQueue** out_work_queue) const; |
| 78 | 82 |
| 79 void SetForceSelectImmediateForTest(bool force_select_immediate); | 83 void SetImmediateStarvationCountForTest(size_t immediate_starvation_count); |
| 80 | 84 |
| 81 private: | 85 private: |
| 82 // Returns the priority which is next after |priority|. | 86 // Returns the priority which is next after |priority|. |
| 83 static TaskQueue::QueuePriority NextPriority( | 87 static TaskQueue::QueuePriority NextPriority( |
| 84 TaskQueue::QueuePriority priority); | 88 TaskQueue::QueuePriority priority); |
| 85 | 89 |
| 86 bool ChooseOldestImmediateTaskWithPriority(TaskQueue::QueuePriority priority, | 90 bool ChooseOldestImmediateTaskWithPriority(TaskQueue::QueuePriority priority, |
| 87 WorkQueue** out_work_queue) const; | 91 WorkQueue** out_work_queue) const; |
| 88 | 92 |
| 89 bool ChooseOldestDelayedTaskWithPriority(TaskQueue::QueuePriority priority, | 93 bool ChooseOldestDelayedTaskWithPriority(TaskQueue::QueuePriority priority, |
| 90 WorkQueue** out_work_queue) const; | 94 WorkQueue** out_work_queue) const; |
| 91 | 95 |
| 96 // Return true if |out_queue| contains the queue with the oldest pending task |
| 97 // from the set of queues of |priority|, or false if all queues of that |
| 98 // priority are empty. In addition |out_chose_delayed_over_immediate| is set |
| 99 // to true iff we chose a delayed work queue in favour of an immediate work |
| 100 // queue. |
| 92 bool ChooseOldestImmediateOrDelayedTaskWithPriority( | 101 bool ChooseOldestImmediateOrDelayedTaskWithPriority( |
| 93 TaskQueue::QueuePriority priority, | 102 TaskQueue::QueuePriority priority, |
| 103 bool* out_chose_delayed_over_immediate, |
| 94 WorkQueue** out_work_queue) const; | 104 WorkQueue** out_work_queue) const; |
| 95 | 105 |
| 96 // Called whenever the selector chooses a task queue for execution with the | 106 // Called whenever the selector chooses a task queue for execution with the |
| 97 // priority |priority|. | 107 // priority |priority|. |
| 98 void DidSelectQueueWithPriority(TaskQueue::QueuePriority priority); | 108 void DidSelectQueueWithPriority(TaskQueue::QueuePriority priority, |
| 109 bool chose_delayed_over_immediate); |
| 99 | 110 |
| 100 // Number of high priority tasks which can be run before a normal priority | 111 // Number of high priority tasks which can be run before a normal priority |
| 101 // task should be selected to prevent starvation. | 112 // task should be selected to prevent starvation. |
| 102 // TODO(rmcilroy): Check if this is a good value. | 113 // TODO(rmcilroy): Check if this is a good value. |
| 103 static const size_t kMaxStarvationTasks = 5; | 114 static const size_t kMaxHighPriorityStarvationTasks = 5; |
| 115 |
| 116 // Maximum number of delayed tasks tasks which can be run while there's a |
| 117 // waiting non-delayed task. |
| 118 static const size_t kMaxDelayedStarvationTasks = 3; |
| 104 | 119 |
| 105 private: | 120 private: |
| 106 base::ThreadChecker main_thread_checker_; | 121 base::ThreadChecker main_thread_checker_; |
| 107 WorkQueueSets delayed_work_queue_sets_; | 122 WorkQueueSets delayed_work_queue_sets_; |
| 108 WorkQueueSets immediate_work_queue_sets_; | 123 WorkQueueSets immediate_work_queue_sets_; |
| 109 bool force_select_immediate_; | 124 size_t immediate_starvation_count_; |
| 110 | 125 size_t high_priority_starvation_count_; |
| 111 size_t starvation_count_; | |
| 112 Observer* task_queue_selector_observer_; // NOT OWNED | 126 Observer* task_queue_selector_observer_; // NOT OWNED |
| 113 DISALLOW_COPY_AND_ASSIGN(TaskQueueSelector); | 127 DISALLOW_COPY_AND_ASSIGN(TaskQueueSelector); |
| 114 }; | 128 }; |
| 115 | 129 |
| 116 } // namespace internal | 130 } // namespace internal |
| 117 } // namespace scheduler | 131 } // namespace scheduler |
| 118 | 132 |
| 119 #endif // COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_SELECTOR_H | 133 #endif // COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_SELECTOR_H |
| OLD | NEW |