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

Side by Side Diff: content/renderer/raster_worker_pool.cc

Issue 1854723002: cc: Simplify task and its derived classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 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 "content/renderer/raster_worker_pool.h" 5 #include "content/renderer/raster_worker_pool.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 }; 102 };
103 103
104 // Lock to exclusively access all the following members that are used to 104 // Lock to exclusively access all the following members that are used to
105 // implement the SequencedTaskRunner interfaces. 105 // implement the SequencedTaskRunner interfaces.
106 base::Lock lock_; 106 base::Lock lock_;
107 107
108 cc::TaskGraphRunner* task_graph_runner_; 108 cc::TaskGraphRunner* task_graph_runner_;
109 // Namespace used to schedule tasks in the task graph runner. 109 // Namespace used to schedule tasks in the task graph runner.
110 cc::NamespaceToken namespace_token_; 110 cc::NamespaceToken namespace_token_;
111 // List of tasks currently queued up for execution. 111 // List of tasks currently queued up for execution.
112 cc::Task::Vector tasks_; 112 cc::DependencyTask::Vector tasks_;
113 // Graph object used for scheduling tasks. 113 // Graph object used for scheduling tasks.
114 cc::TaskGraph graph_; 114 cc::TaskGraph graph_;
115 // Cached vector to avoid allocation when getting the list of complete 115 // Cached vector to avoid allocation when getting the list of complete
116 // tasks. 116 // tasks.
117 cc::Task::Vector completed_tasks_; 117 cc::DependencyTask::Vector completed_tasks_;
118 }; 118 };
119 119
120 RasterWorkerPool::RasterWorkerPool() 120 RasterWorkerPool::RasterWorkerPool()
121 : namespace_token_(GetNamespaceToken()), 121 : namespace_token_(GetNamespaceToken()),
122 has_ready_to_run_foreground_tasks_cv_(&lock_), 122 has_ready_to_run_foreground_tasks_cv_(&lock_),
123 has_ready_to_run_background_tasks_cv_(&lock_), 123 has_ready_to_run_background_tasks_cv_(&lock_),
124 has_namespaces_with_finished_running_tasks_cv_(&lock_), 124 has_namespaces_with_finished_running_tasks_cv_(&lock_),
125 shutdown_(false) {} 125 shutdown_(false) {}
126 126
127 void RasterWorkerPool::Start(int num_threads) { 127 void RasterWorkerPool::Start(int num_threads) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 bool RasterWorkerPool::PostDelayedTask( 191 bool RasterWorkerPool::PostDelayedTask(
192 const tracked_objects::Location& from_here, 192 const tracked_objects::Location& from_here,
193 const base::Closure& task, 193 const base::Closure& task,
194 base::TimeDelta delay) { 194 base::TimeDelta delay) {
195 base::AutoLock lock(lock_); 195 base::AutoLock lock(lock_);
196 196
197 // Remove completed tasks. 197 // Remove completed tasks.
198 DCHECK(completed_tasks_.empty()); 198 DCHECK(completed_tasks_.empty());
199 CollectCompletedTasksWithLockAcquired(namespace_token_, &completed_tasks_); 199 CollectCompletedTasksWithLockAcquired(namespace_token_, &completed_tasks_);
200 200
201 cc::Task::Vector::iterator end = std::remove_if( 201 cc::DependencyTask::Vector::iterator end = std::remove_if(
202 tasks_.begin(), tasks_.end(), [this](const scoped_refptr<cc::Task>& e) { 202 tasks_.begin(), tasks_.end(),
203 [this](const scoped_refptr<cc::DependencyTask>& e) {
203 return std::find(this->completed_tasks_.begin(), 204 return std::find(this->completed_tasks_.begin(),
204 this->completed_tasks_.end(), 205 this->completed_tasks_.end(),
205 e) != this->completed_tasks_.end(); 206 e) != this->completed_tasks_.end();
206 }); 207 });
207 tasks_.erase(end, tasks_.end()); 208 tasks_.erase(end, tasks_.end());
208 209
209 tasks_.push_back(make_scoped_refptr(new ClosureTask(task))); 210 tasks_.push_back(make_scoped_refptr(new ClosureTask(task)));
210 graph_.Reset(); 211 graph_.Reset();
211 for (const auto& graph_task : tasks_) { 212 for (const auto& graph_task : tasks_) {
212 // Delayed tasks are assigned FOREGROUND category, ensuring that they run as 213 // Delayed tasks are assigned FOREGROUND category, ensuring that they run as
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 has_namespaces_with_finished_running_tasks_cv_.Wait(); 309 has_namespaces_with_finished_running_tasks_cv_.Wait();
309 310
310 // There may be other namespaces that have finished running tasks, so wake 311 // There may be other namespaces that have finished running tasks, so wake
311 // up another origin thread. 312 // up another origin thread.
312 has_namespaces_with_finished_running_tasks_cv_.Signal(); 313 has_namespaces_with_finished_running_tasks_cv_.Signal();
313 } 314 }
314 } 315 }
315 316
316 void RasterWorkerPool::CollectCompletedTasks( 317 void RasterWorkerPool::CollectCompletedTasks(
317 cc::NamespaceToken token, 318 cc::NamespaceToken token,
318 cc::Task::Vector* completed_tasks) { 319 cc::DependencyTask::Vector* completed_tasks) {
319 TRACE_EVENT0("disabled-by-default-cc.debug", 320 TRACE_EVENT0("disabled-by-default-cc.debug",
320 "RasterWorkerPool::CollectCompletedTasks"); 321 "RasterWorkerPool::CollectCompletedTasks");
321 322
322 { 323 {
323 base::AutoLock lock(lock_); 324 base::AutoLock lock(lock_);
324 CollectCompletedTasksWithLockAcquired(token, completed_tasks); 325 CollectCompletedTasksWithLockAcquired(token, completed_tasks);
325 } 326 }
326 } 327 }
327 328
328 void RasterWorkerPool::CollectCompletedTasksWithLockAcquired( 329 void RasterWorkerPool::CollectCompletedTasksWithLockAcquired(
329 cc::NamespaceToken token, 330 cc::NamespaceToken token,
330 cc::Task::Vector* completed_tasks) { 331 cc::DependencyTask::Vector* completed_tasks) {
331 DCHECK(token.IsValid()); 332 DCHECK(token.IsValid());
332 work_queue_.CollectCompletedTasks(token, completed_tasks); 333 work_queue_.CollectCompletedTasks(token, completed_tasks);
333 } 334 }
334 335
335 bool RasterWorkerPool::RunTaskWithLockAcquired( 336 bool RasterWorkerPool::RunTaskWithLockAcquired(
336 const std::vector<cc::TaskCategory>& categories) { 337 const std::vector<cc::TaskCategory>& categories) {
337 for (const auto& category : categories) { 338 for (const auto& category : categories) {
338 if (ShouldRunTaskForCategoryWithLockAcquired(category)) { 339 if (ShouldRunTaskForCategoryWithLockAcquired(category)) {
339 RunTaskInCategoryWithLockAcquired(category); 340 RunTaskInCategoryWithLockAcquired(category);
340 return true; 341 return true;
341 } 342 }
342 } 343 }
343 return false; 344 return false;
344 } 345 }
345 346
346 void RasterWorkerPool::RunTaskInCategoryWithLockAcquired( 347 void RasterWorkerPool::RunTaskInCategoryWithLockAcquired(
347 cc::TaskCategory category) { 348 cc::TaskCategory category) {
348 TRACE_EVENT0("toplevel", "TaskGraphRunner::RunTask"); 349 TRACE_EVENT0("toplevel", "TaskGraphRunner::RunTask");
349 350
350 lock_.AssertAcquired(); 351 lock_.AssertAcquired();
351 352
352 auto prioritized_task = work_queue_.GetNextTaskToRun(category); 353 auto prioritized_task = work_queue_.GetNextTaskToRun(category);
353 cc::Task* task = prioritized_task.task; 354 cc::DependencyTask* task = prioritized_task.task;
354 355
355 // There may be more work available, so wake up another worker thread. 356 // There may be more work available, so wake up another worker thread.
356 SignalHasReadyToRunTasksWithLockAcquired(); 357 SignalHasReadyToRunTasksWithLockAcquired();
357 358
358 // Call WillRun() before releasing |lock_| and running task. 359 // Call WillRun() before releasing |lock_| and running task.
359 task->WillRun(); 360 task->WillRun();
360 361
361 { 362 {
362 base::AutoUnlock unlock(lock_); 363 base::AutoUnlock unlock(lock_);
363 364
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 428
428 // Overridden from cc::Task: 429 // Overridden from cc::Task:
429 void RasterWorkerPool::ClosureTask::RunOnWorkerThread() { 430 void RasterWorkerPool::ClosureTask::RunOnWorkerThread() {
430 closure_.Run(); 431 closure_.Run();
431 closure_.Reset(); 432 closure_.Reset();
432 } 433 }
433 434
434 RasterWorkerPool::ClosureTask::~ClosureTask() {} 435 RasterWorkerPool::ClosureTask::~ClosureTask() {}
435 436
436 } // namespace content 437 } // namespace content
OLDNEW
« cc/raster/dependency_task.cc ('K') | « content/renderer/raster_worker_pool.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698