| 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 |
| 63 // Completed tasks not yet collected by origin thread. | 66 // Completed tasks not yet collected by origin thread. |
| 64 Task::Vector completed_tasks; | 67 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 [](const TaskNamespaceMap::value_type& entry) { | 138 [](const TaskNamespaceMap::value_type& entry) { |
| 139 return !HasFinishedRunningTasksInNamespace(&entry.second); | 139 return !HasFinishedRunningTasksInNamespace(&entry.second); |
| 140 }) == namespaces_.end(); | 140 }) == namespaces_.end(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 const std::map<uint16_t, TaskNamespace::Vector>& ready_to_run_namespaces() | 143 const std::map<uint16_t, TaskNamespace::Vector>& ready_to_run_namespaces() |
| 144 const { | 144 const { |
| 145 return ready_to_run_namespaces_; | 145 return ready_to_run_namespaces_; |
| 146 } | 146 } |
| 147 | 147 |
| 148 size_t NumRunningTasksForCategory(uint16_t category) const { |
| 149 size_t count = 0; |
| 150 for (const auto& task_namespace_entry : namespaces_) { |
| 151 const auto& running_tasks = task_namespace_entry.second.running_tasks; |
| 152 const auto& running_tasks_for_category = running_tasks.find(category); |
| 153 if (running_tasks_for_category != running_tasks.cend()) { |
| 154 count += running_tasks_for_category->second.size(); |
| 155 } |
| 156 } |
| 157 return count; |
| 158 } |
| 159 |
| 148 // Helper function which ensures that graph dependencies were correctly | 160 // Helper function which ensures that graph dependencies were correctly |
| 149 // configured. | 161 // configured. |
| 150 static bool DependencyMismatch(const TaskGraph* graph); | 162 static bool DependencyMismatch(const TaskGraph* graph); |
| 151 | 163 |
| 152 private: | 164 private: |
| 153 // Helper class used to provide NamespaceToken comparison to TaskNamespaceMap. | 165 // Helper class used to provide NamespaceToken comparison to TaskNamespaceMap. |
| 154 class CompareToken { | 166 class CompareToken { |
| 155 public: | 167 public: |
| 156 bool operator()(const NamespaceToken& lhs, | 168 bool operator()(const NamespaceToken& lhs, |
| 157 const NamespaceToken& rhs) const { | 169 const NamespaceToken& rhs) const { |
| 158 return lhs.id_ < rhs.id_; | 170 return lhs.id_ < rhs.id_; |
| 159 } | 171 } |
| 160 }; | 172 }; |
| 161 | 173 |
| 162 using TaskNamespaceMap = | 174 using TaskNamespaceMap = |
| 163 std::map<NamespaceToken, TaskNamespace, CompareToken>; | 175 std::map<NamespaceToken, TaskNamespace, CompareToken>; |
| 164 | 176 |
| 165 TaskNamespaceMap namespaces_; | 177 TaskNamespaceMap namespaces_; |
| 166 | 178 |
| 167 // Map from category to a vector of ready to run namespaces for that category. | 179 // Map from category to a vector of ready to run namespaces for that category. |
| 168 std::map<uint16_t, TaskNamespace::Vector> ready_to_run_namespaces_; | 180 std::map<uint16_t, TaskNamespace::Vector> ready_to_run_namespaces_; |
| 169 | 181 |
| 170 // Provides a unique id to each NamespaceToken. | 182 // Provides a unique id to each NamespaceToken. |
| 171 int next_namespace_id_; | 183 int next_namespace_id_; |
| 172 }; | 184 }; |
| 173 | 185 |
| 174 } // namespace cc | 186 } // namespace cc |
| 175 | 187 |
| 176 #endif // CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ | 188 #endif // CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ |
| OLD | NEW |