Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(825)

Side by Side Diff: cc/raster/task_graph_work_queue.h

Issue 1666283002: Reland - Refactor signaling in RWP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: feedback Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 27 matching lines...) Expand all
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 task_namespace->running_tasks.empty() && 115 return std::all_of(
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 }) &&
116 !HasReadyToRunTasksInNamespace(task_namespace); 121 !HasReadyToRunTasksInNamespace(task_namespace);
117 } 122 }
118 123
119 bool HasReadyToRunTasks() const { 124 bool HasReadyToRunTasks() const {
120 return std::find_if(ready_to_run_namespaces_.begin(), 125 return std::find_if(ready_to_run_namespaces_.begin(),
121 ready_to_run_namespaces_.end(), 126 ready_to_run_namespaces_.end(),
122 [](const std::pair<uint16_t, TaskNamespace::Vector>& 127 [](const std::pair<uint16_t, TaskNamespace::Vector>&
123 ready_to_run_namespaces) { 128 ready_to_run_namespaces) {
124 return !ready_to_run_namespaces.second.empty(); 129 return !ready_to_run_namespaces.second.empty();
125 }) != ready_to_run_namespaces_.end(); 130 }) != ready_to_run_namespaces_.end();
(...skipping 12 matching lines...) Expand all
138 [](const TaskNamespaceMap::value_type& entry) { 143 [](const TaskNamespaceMap::value_type& entry) {
139 return !HasFinishedRunningTasksInNamespace(&entry.second); 144 return !HasFinishedRunningTasksInNamespace(&entry.second);
140 }) == namespaces_.end(); 145 }) == namespaces_.end();
141 } 146 }
142 147
143 const std::map<uint16_t, TaskNamespace::Vector>& ready_to_run_namespaces() 148 const std::map<uint16_t, TaskNamespace::Vector>& ready_to_run_namespaces()
144 const { 149 const {
145 return ready_to_run_namespaces_; 150 return ready_to_run_namespaces_;
146 } 151 }
147 152
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
148 // Helper function which ensures that graph dependencies were correctly 165 // Helper function which ensures that graph dependencies were correctly
149 // configured. 166 // configured.
150 static bool DependencyMismatch(const TaskGraph* graph); 167 static bool DependencyMismatch(const TaskGraph* graph);
151 168
152 private: 169 private:
153 // Helper class used to provide NamespaceToken comparison to TaskNamespaceMap. 170 // Helper class used to provide NamespaceToken comparison to TaskNamespaceMap.
154 class CompareToken { 171 class CompareToken {
155 public: 172 public:
156 bool operator()(const NamespaceToken& lhs, 173 bool operator()(const NamespaceToken& lhs,
157 const NamespaceToken& rhs) const { 174 const NamespaceToken& rhs) const {
158 return lhs.id_ < rhs.id_; 175 return lhs.id_ < rhs.id_;
159 } 176 }
160 }; 177 };
161 178
162 using TaskNamespaceMap = 179 using TaskNamespaceMap =
163 std::map<NamespaceToken, TaskNamespace, CompareToken>; 180 std::map<NamespaceToken, TaskNamespace, CompareToken>;
164 181
165 TaskNamespaceMap namespaces_; 182 TaskNamespaceMap namespaces_;
166 183
167 // Map from category to a vector of ready to run namespaces for that category. 184 // 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_; 185 std::map<uint16_t, TaskNamespace::Vector> ready_to_run_namespaces_;
169 186
170 // Provides a unique id to each NamespaceToken. 187 // Provides a unique id to each NamespaceToken.
171 int next_namespace_id_; 188 int next_namespace_id_;
172 }; 189 };
173 190
174 } // namespace cc 191 } // namespace cc
175 192
176 #endif // CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ 193 #endif // CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_
OLDNEW
« no previous file with comments | « no previous file | cc/raster/task_graph_work_queue.cc » ('j') | content/renderer/raster_worker_pool.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698