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

Side by Side Diff: cc/raster/single_thread_task_graph_runner.cc

Issue 1521423003: Revert of TaskGraphRunner Group support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor
Patch Set: Created 5 years 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/single_thread_task_graph_runner.h ('k') | cc/raster/synchronous_task_graph_runner.h » ('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 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 #include "cc/raster/single_thread_task_graph_runner.h" 5 #include "cc/raster/single_thread_task_graph_runner.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/threading/simple_thread.h" 9 #include "base/threading/simple_thread.h"
10 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 { 105 {
106 base::AutoLock lock(lock_); 106 base::AutoLock lock(lock_);
107 work_queue_.CollectCompletedTasks(token, completed_tasks); 107 work_queue_.CollectCompletedTasks(token, completed_tasks);
108 } 108 }
109 } 109 }
110 110
111 void SingleThreadTaskGraphRunner::Run() { 111 void SingleThreadTaskGraphRunner::Run() {
112 base::AutoLock lock(lock_); 112 base::AutoLock lock(lock_);
113 113
114 while (true) { 114 while (true) {
115 if (!RunTaskWithLockAcquired()) { 115 if (!work_queue_.HasReadyToRunTasks()) {
116 // Exit when shutdown is set and no more tasks are pending. 116 // Exit when shutdown is set and no more tasks are pending.
117 if (shutdown_) 117 if (shutdown_)
118 break; 118 break;
119 119
120 // Wait for more tasks. 120 // Wait for more tasks.
121 has_ready_to_run_tasks_cv_.Wait(); 121 has_ready_to_run_tasks_cv_.Wait();
122 continue; 122 continue;
123 } 123 }
124
125 RunTaskWithLockAcquired();
124 } 126 }
125 } 127 }
126 128
127 bool SingleThreadTaskGraphRunner::RunTaskWithLockAcquired() { 129 void SingleThreadTaskGraphRunner::RunTaskWithLockAcquired() {
128 TRACE_EVENT0("toplevel", 130 TRACE_EVENT0("toplevel",
129 "SingleThreadTaskGraphRunner::RunTaskWithLockAcquired"); 131 "SingleThreadTaskGraphRunner::RunTaskWithLockAcquired");
130 132
131 lock_.AssertAcquired(); 133 lock_.AssertAcquired();
132 134
133 // Find the first category with any tasks to run. This task graph runner 135 auto prioritized_task = work_queue_.GetNextTaskToRun();
134 // treats categories as an additional priority.
135 const auto& ready_to_run_namespaces = work_queue_.ready_to_run_namespaces();
136 auto found = std::find_if(
137 ready_to_run_namespaces.cbegin(), ready_to_run_namespaces.cend(),
138 [](const std::pair<uint16_t, TaskGraphWorkQueue::TaskNamespace::Vector>&
139 pair) { return !pair.second.empty(); });
140
141 if (found == ready_to_run_namespaces.cend()) {
142 return false;
143 }
144
145 const uint16_t category = found->first;
146 auto prioritized_task = work_queue_.GetNextTaskToRun(category);
147 Task* task = prioritized_task.task; 136 Task* task = prioritized_task.task;
148 137
149 // Call WillRun() before releasing |lock_| and running task. 138 // Call WillRun() before releasing |lock_| and running task.
150 task->WillRun(); 139 task->WillRun();
151 140
152 { 141 {
153 base::AutoUnlock unlock(lock_); 142 base::AutoUnlock unlock(lock_);
154 task->RunOnWorkerThread(); 143 task->RunOnWorkerThread();
155 } 144 }
156 145
157 // This will mark task as finished running. 146 // This will mark task as finished running.
158 task->DidRun(); 147 task->DidRun();
159 148
160 work_queue_.CompleteTask(prioritized_task); 149 work_queue_.CompleteTask(prioritized_task);
161 150
162 // If namespace has finished running all tasks, wake up origin thread. 151 // If namespace has finished running all tasks, wake up origin thread.
163 if (work_queue_.HasFinishedRunningTasksInNamespace( 152 if (work_queue_.HasFinishedRunningTasksInNamespace(
164 prioritized_task.task_namespace)) 153 prioritized_task.task_namespace))
165 has_namespaces_with_finished_running_tasks_cv_.Signal(); 154 has_namespaces_with_finished_running_tasks_cv_.Signal();
166
167 return true;
168 } 155 }
169 156
170 } // namespace cc 157 } // namespace cc
OLDNEW
« no previous file with comments | « cc/raster/single_thread_task_graph_runner.h ('k') | cc/raster/synchronous_task_graph_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698