| 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 CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ | 5 #ifndef CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ |
| 6 #define CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ | 6 #define CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 TaskNamespace(); | 53 TaskNamespace(); |
| 54 ~TaskNamespace(); | 54 ~TaskNamespace(); |
| 55 | 55 |
| 56 // Current task graph. | 56 // Current task graph. |
| 57 TaskGraph graph; | 57 TaskGraph graph; |
| 58 | 58 |
| 59 // Map from category to a vector of tasks that are ready to run for that | 59 // Map from category to a vector of tasks that are ready to run for that |
| 60 // category. | 60 // category. |
| 61 std::map<uint16_t, PrioritizedTask::Vector> ready_to_run_tasks; | 61 std::map<uint16_t, PrioritizedTask::Vector> ready_to_run_tasks; |
| 62 | 62 |
| 63 // This set contains all currently running tasks. | |
| 64 std::map<uint16_t, Task::Vector> running_tasks; | |
| 65 | |
| 66 // Completed tasks not yet collected by origin thread. | 63 // Completed tasks not yet collected by origin thread. |
| 67 Task::Vector completed_tasks; | 64 Task::Vector completed_tasks; |
| 65 |
| 66 // This set contains all currently running tasks. |
| 67 Task::Vector running_tasks; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 TaskGraphWorkQueue(); | 70 TaskGraphWorkQueue(); |
| 71 virtual ~TaskGraphWorkQueue(); | 71 virtual ~TaskGraphWorkQueue(); |
| 72 | 72 |
| 73 // Gets a NamespaceToken which is guaranteed to be unique within this | 73 // Gets a NamespaceToken which is guaranteed to be unique within this |
| 74 // TaskGraphWorkQueue. | 74 // TaskGraphWorkQueue. |
| 75 NamespaceToken GetNamespaceToken(); | 75 NamespaceToken GetNamespaceToken(); |
| 76 | 76 |
| 77 // Updates a TaskNamespace with a new TaskGraph to run. This cancels any | 77 // Updates a TaskNamespace with a new TaskGraph to run. This cancels any |
| (...skipping 27 matching lines...) Expand all Loading... |
| 105 return std::find_if(task_namespace->ready_to_run_tasks.begin(), | 105 return std::find_if(task_namespace->ready_to_run_tasks.begin(), |
| 106 task_namespace->ready_to_run_tasks.end(), | 106 task_namespace->ready_to_run_tasks.end(), |
| 107 [](const std::pair<uint16_t, PrioritizedTask::Vector>& | 107 [](const std::pair<uint16_t, PrioritizedTask::Vector>& |
| 108 ready_to_run_tasks) { | 108 ready_to_run_tasks) { |
| 109 return !ready_to_run_tasks.second.empty(); | 109 return !ready_to_run_tasks.second.empty(); |
| 110 }) != task_namespace->ready_to_run_tasks.end(); | 110 }) != task_namespace->ready_to_run_tasks.end(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 static bool HasFinishedRunningTasksInNamespace( | 113 static bool HasFinishedRunningTasksInNamespace( |
| 114 const TaskNamespace* task_namespace) { | 114 const TaskNamespace* task_namespace) { |
| 115 return std::all_of( | 115 return task_namespace->running_tasks.empty() && |
| 116 task_namespace->running_tasks.cbegin(), | |
| 117 task_namespace->running_tasks.cend(), | |
| 118 [](const std::pair<uint16_t, Task::Vector>& tasks_entry) { | |
| 119 return tasks_entry.second.empty(); | |
| 120 }) && | |
| 121 !HasReadyToRunTasksInNamespace(task_namespace); | 116 !HasReadyToRunTasksInNamespace(task_namespace); |
| 122 } | 117 } |
| 123 | 118 |
| 124 bool HasReadyToRunTasks() const { | 119 bool HasReadyToRunTasks() const { |
| 125 return std::find_if(ready_to_run_namespaces_.begin(), | 120 return std::find_if(ready_to_run_namespaces_.begin(), |
| 126 ready_to_run_namespaces_.end(), | 121 ready_to_run_namespaces_.end(), |
| 127 [](const std::pair<uint16_t, TaskNamespace::Vector>& | 122 [](const std::pair<uint16_t, TaskNamespace::Vector>& |
| 128 ready_to_run_namespaces) { | 123 ready_to_run_namespaces) { |
| 129 return !ready_to_run_namespaces.second.empty(); | 124 return !ready_to_run_namespaces.second.empty(); |
| 130 }) != ready_to_run_namespaces_.end(); | 125 }) != ready_to_run_namespaces_.end(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 143 [](const TaskNamespaceMap::value_type& entry) { | 138 [](const TaskNamespaceMap::value_type& entry) { |
| 144 return !HasFinishedRunningTasksInNamespace(&entry.second); | 139 return !HasFinishedRunningTasksInNamespace(&entry.second); |
| 145 }) == namespaces_.end(); | 140 }) == namespaces_.end(); |
| 146 } | 141 } |
| 147 | 142 |
| 148 const std::map<uint16_t, TaskNamespace::Vector>& ready_to_run_namespaces() | 143 const std::map<uint16_t, TaskNamespace::Vector>& ready_to_run_namespaces() |
| 149 const { | 144 const { |
| 150 return ready_to_run_namespaces_; | 145 return ready_to_run_namespaces_; |
| 151 } | 146 } |
| 152 | 147 |
| 153 size_t NumRunningTasksForCategory(uint16_t category) const { | |
| 154 size_t count = 0; | |
| 155 for (const auto& task_namespace_entry : namespaces_) { | |
| 156 const auto& running_tasks = task_namespace_entry.second.running_tasks; | |
| 157 const auto& running_tasks_for_category = running_tasks.find(category); | |
| 158 if (running_tasks_for_category != running_tasks.cend()) { | |
| 159 count += running_tasks_for_category->second.size(); | |
| 160 } | |
| 161 } | |
| 162 return count; | |
| 163 } | |
| 164 | |
| 165 // Helper function which ensures that graph dependencies were correctly | 148 // Helper function which ensures that graph dependencies were correctly |
| 166 // configured. | 149 // configured. |
| 167 static bool DependencyMismatch(const TaskGraph* graph); | 150 static bool DependencyMismatch(const TaskGraph* graph); |
| 168 | 151 |
| 169 private: | 152 private: |
| 170 // Helper class used to provide NamespaceToken comparison to TaskNamespaceMap. | 153 // Helper class used to provide NamespaceToken comparison to TaskNamespaceMap. |
| 171 class CompareToken { | 154 class CompareToken { |
| 172 public: | 155 public: |
| 173 bool operator()(const NamespaceToken& lhs, | 156 bool operator()(const NamespaceToken& lhs, |
| 174 const NamespaceToken& rhs) const { | 157 const NamespaceToken& rhs) const { |
| 175 return lhs.id_ < rhs.id_; | 158 return lhs.id_ < rhs.id_; |
| 176 } | 159 } |
| 177 }; | 160 }; |
| 178 | 161 |
| 179 using TaskNamespaceMap = | 162 using TaskNamespaceMap = |
| 180 std::map<NamespaceToken, TaskNamespace, CompareToken>; | 163 std::map<NamespaceToken, TaskNamespace, CompareToken>; |
| 181 | 164 |
| 182 TaskNamespaceMap namespaces_; | 165 TaskNamespaceMap namespaces_; |
| 183 | 166 |
| 184 // Map from category to a vector of ready to run namespaces for that category. | 167 // Map from category to a vector of ready to run namespaces for that category. |
| 185 std::map<uint16_t, TaskNamespace::Vector> ready_to_run_namespaces_; | 168 std::map<uint16_t, TaskNamespace::Vector> ready_to_run_namespaces_; |
| 186 | 169 |
| 187 // Provides a unique id to each NamespaceToken. | 170 // Provides a unique id to each NamespaceToken. |
| 188 int next_namespace_id_; | 171 int next_namespace_id_; |
| 189 }; | 172 }; |
| 190 | 173 |
| 191 } // namespace cc | 174 } // namespace cc |
| 192 | 175 |
| 193 #endif // CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ | 176 #endif // CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ |
| OLD | NEW |