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

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: Fix refcounting issue. 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
« no previous file with comments | « cc/raster/synchronous_task_graph_runner.cc ('k') | cc/raster/task_graph_work_queue.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 10 matching lines...) Expand all
21 // responsible for all necessary locking. 21 // responsible for all necessary locking.
22 // 22 //
23 // Tasks in the queue are divided into categories. Tasks from a single graph may 23 // Tasks in the queue are divided into categories. Tasks from a single graph may
24 // be put into different categories, each of which is prioritized independently 24 // be put into different categories, each of which is prioritized independently
25 // from the others. It is up to the implementation of TaskGraphRunner to 25 // from the others. It is up to the implementation of TaskGraphRunner to
26 // define the meaning of the categories and handle them appropriately. 26 // define the meaning of the categories and handle them appropriately.
27 class CC_EXPORT TaskGraphWorkQueue { 27 class CC_EXPORT TaskGraphWorkQueue {
28 public: 28 public:
29 struct TaskNamespace; 29 struct TaskNamespace;
30 30
31 struct PrioritizedTask { 31 struct CC_EXPORT PrioritizedTask {
32 typedef std::vector<PrioritizedTask> Vector; 32 typedef std::vector<PrioritizedTask> Vector;
33 33
34 PrioritizedTask(Task* task, 34 PrioritizedTask(Task* task,
35 TaskNamespace* task_namespace, 35 TaskNamespace* task_namespace,
36 uint16_t category, 36 uint16_t category,
37 uint16_t priority) 37 uint16_t priority);
38 : task(task), 38 ~PrioritizedTask();
39 task_namespace(task_namespace),
40 category(category),
41 priority(priority) {}
42 39
43 Task* task; 40 scoped_refptr<Task> task;
reveman 2016/02/24 18:53:00 hm, not sure about this. I'm worried this will mak
ericrk 2016/02/24 19:30:43 Introduced a new type, CategorizedTask, which refc
44 TaskNamespace* task_namespace; 41 TaskNamespace* task_namespace;
45 uint16_t category; 42 uint16_t category;
46 uint16_t priority; 43 uint16_t priority;
47 }; 44 };
48 45
49 // Helper classes and static methods used by dependent classes. 46 // Helper classes and static methods used by dependent classes.
50 struct TaskNamespace { 47 struct TaskNamespace {
51 typedef std::vector<TaskNamespace*> Vector; 48 typedef std::vector<TaskNamespace*> Vector;
52 49
53 TaskNamespace(); 50 TaskNamespace();
54 ~TaskNamespace(); 51 ~TaskNamespace();
55 52
56 // Current task graph. 53 // Current task graph.
57 TaskGraph graph; 54 TaskGraph graph;
58 55
59 // Map from category to a vector of tasks that are ready to run for that 56 // Map from category to a vector of tasks that are ready to run for that
60 // category. 57 // category.
61 std::map<uint16_t, PrioritizedTask::Vector> ready_to_run_tasks; 58 std::map<uint16_t, PrioritizedTask::Vector> ready_to_run_tasks;
62 59
63 // Completed tasks not yet collected by origin thread. 60 // Completed tasks not yet collected by origin thread.
64 Task::Vector completed_tasks; 61 Task::Vector completed_tasks;
65 62
66 // This set contains all currently running tasks. 63 // This set contains all currently running tasks.
67 Task::Vector running_tasks; 64 PrioritizedTask::Vector running_tasks;
68 }; 65 };
69 66
70 TaskGraphWorkQueue(); 67 TaskGraphWorkQueue();
71 virtual ~TaskGraphWorkQueue(); 68 virtual ~TaskGraphWorkQueue();
72 69
73 // Gets a NamespaceToken which is guaranteed to be unique within this 70 // Gets a NamespaceToken which is guaranteed to be unique within this
74 // TaskGraphWorkQueue. 71 // TaskGraphWorkQueue.
75 NamespaceToken GetNamespaceToken(); 72 NamespaceToken GetNamespaceToken();
76 73
77 // Updates a TaskNamespace with a new TaskGraph to run. This cancels any 74 // Updates a TaskNamespace with a new TaskGraph to run. This cancels any
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 [](const TaskNamespaceMap::value_type& entry) { 135 [](const TaskNamespaceMap::value_type& entry) {
139 return !HasFinishedRunningTasksInNamespace(&entry.second); 136 return !HasFinishedRunningTasksInNamespace(&entry.second);
140 }) == namespaces_.end(); 137 }) == namespaces_.end();
141 } 138 }
142 139
143 const std::map<uint16_t, TaskNamespace::Vector>& ready_to_run_namespaces() 140 const std::map<uint16_t, TaskNamespace::Vector>& ready_to_run_namespaces()
144 const { 141 const {
145 return ready_to_run_namespaces_; 142 return ready_to_run_namespaces_;
146 } 143 }
147 144
145 size_t NumRunningTasksForCategory(uint16_t category) const {
146 size_t count = 0;
147 for (const auto& task_namespace_entry : namespaces_) {
148 for (const auto& prioritized_task :
149 task_namespace_entry.second.running_tasks) {
150 if (prioritized_task.category == category) {
151 count++;
152 }
153 }
154 }
155 return count;
156 }
157
148 // Helper function which ensures that graph dependencies were correctly 158 // Helper function which ensures that graph dependencies were correctly
149 // configured. 159 // configured.
150 static bool DependencyMismatch(const TaskGraph* graph); 160 static bool DependencyMismatch(const TaskGraph* graph);
151 161
152 private: 162 private:
153 // Helper class used to provide NamespaceToken comparison to TaskNamespaceMap. 163 // Helper class used to provide NamespaceToken comparison to TaskNamespaceMap.
154 class CompareToken { 164 class CompareToken {
155 public: 165 public:
156 bool operator()(const NamespaceToken& lhs, 166 bool operator()(const NamespaceToken& lhs,
157 const NamespaceToken& rhs) const { 167 const NamespaceToken& rhs) const {
158 return lhs.id_ < rhs.id_; 168 return lhs.id_ < rhs.id_;
159 } 169 }
160 }; 170 };
161 171
162 using TaskNamespaceMap = 172 using TaskNamespaceMap =
163 std::map<NamespaceToken, TaskNamespace, CompareToken>; 173 std::map<NamespaceToken, TaskNamespace, CompareToken>;
164 174
165 TaskNamespaceMap namespaces_; 175 TaskNamespaceMap namespaces_;
166 176
167 // Map from category to a vector of ready to run namespaces for that category. 177 // 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_; 178 std::map<uint16_t, TaskNamespace::Vector> ready_to_run_namespaces_;
169 179
170 // Provides a unique id to each NamespaceToken. 180 // Provides a unique id to each NamespaceToken.
171 int next_namespace_id_; 181 int next_namespace_id_;
172 }; 182 };
173 183
174 } // namespace cc 184 } // namespace cc
175 185
176 #endif // CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_ 186 #endif // CC_RASTER_TASK_GRAPH_WORK_QUEUE_H_
OLDNEW
« no previous file with comments | « cc/raster/synchronous_task_graph_runner.cc ('k') | cc/raster/task_graph_work_queue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698