| OLD | NEW |
| 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 Loading... |
| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 bool RasterWorkerPool::PostDelayedTask( | 188 bool RasterWorkerPool::PostDelayedTask( |
| 189 const tracked_objects::Location& from_here, | 189 const tracked_objects::Location& from_here, |
| 190 const base::Closure& task, | 190 const base::Closure& task, |
| 191 base::TimeDelta delay) { | 191 base::TimeDelta delay) { |
| 192 base::AutoLock lock(lock_); | 192 base::AutoLock lock(lock_); |
| 193 | 193 |
| 194 // Remove completed tasks. | 194 // Remove completed tasks. |
| 195 DCHECK(completed_tasks_.empty()); | 195 DCHECK(completed_tasks_.empty()); |
| 196 CollectCompletedTasksWithLockAcquired(namespace_token_, &completed_tasks_); | 196 CollectCompletedTasksWithLockAcquired(namespace_token_, &completed_tasks_); |
| 197 | 197 |
| 198 cc::Task::Vector::iterator end = std::remove_if( | 198 cc::DependencyTask::Vector::iterator end = std::remove_if( |
| 199 tasks_.begin(), tasks_.end(), [this](const scoped_refptr<cc::Task>& e) { | 199 tasks_.begin(), tasks_.end(), |
| 200 [this](const scoped_refptr<cc::DependencyTask>& e) { |
| 200 return std::find(this->completed_tasks_.begin(), | 201 return std::find(this->completed_tasks_.begin(), |
| 201 this->completed_tasks_.end(), | 202 this->completed_tasks_.end(), |
| 202 e) != this->completed_tasks_.end(); | 203 e) != this->completed_tasks_.end(); |
| 203 }); | 204 }); |
| 204 tasks_.erase(end, tasks_.end()); | 205 tasks_.erase(end, tasks_.end()); |
| 205 | 206 |
| 206 tasks_.push_back(make_scoped_refptr(new ClosureTask(task))); | 207 tasks_.push_back(make_scoped_refptr(new ClosureTask(task))); |
| 207 graph_.Reset(); | 208 graph_.Reset(); |
| 208 for (const auto& graph_task : tasks_) { | 209 for (const auto& graph_task : tasks_) { |
| 209 // Delayed tasks are assigned FOREGROUND category, ensuring that they run as | 210 // Delayed tasks are assigned FOREGROUND category, ensuring that they run as |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 has_namespaces_with_finished_running_tasks_cv_.Wait(); | 306 has_namespaces_with_finished_running_tasks_cv_.Wait(); |
| 306 | 307 |
| 307 // There may be other namespaces that have finished running tasks, so wake | 308 // There may be other namespaces that have finished running tasks, so wake |
| 308 // up another origin thread. | 309 // up another origin thread. |
| 309 has_namespaces_with_finished_running_tasks_cv_.Signal(); | 310 has_namespaces_with_finished_running_tasks_cv_.Signal(); |
| 310 } | 311 } |
| 311 } | 312 } |
| 312 | 313 |
| 313 void RasterWorkerPool::CollectCompletedTasks( | 314 void RasterWorkerPool::CollectCompletedTasks( |
| 314 cc::NamespaceToken token, | 315 cc::NamespaceToken token, |
| 315 cc::Task::Vector* completed_tasks) { | 316 cc::DependencyTask::Vector* completed_tasks) { |
| 316 TRACE_EVENT0("disabled-by-default-cc.debug", | 317 TRACE_EVENT0("disabled-by-default-cc.debug", |
| 317 "RasterWorkerPool::CollectCompletedTasks"); | 318 "RasterWorkerPool::CollectCompletedTasks"); |
| 318 | 319 |
| 319 { | 320 { |
| 320 base::AutoLock lock(lock_); | 321 base::AutoLock lock(lock_); |
| 321 CollectCompletedTasksWithLockAcquired(token, completed_tasks); | 322 CollectCompletedTasksWithLockAcquired(token, completed_tasks); |
| 322 } | 323 } |
| 323 } | 324 } |
| 324 | 325 |
| 325 void RasterWorkerPool::CollectCompletedTasksWithLockAcquired( | 326 void RasterWorkerPool::CollectCompletedTasksWithLockAcquired( |
| 326 cc::NamespaceToken token, | 327 cc::NamespaceToken token, |
| 327 cc::Task::Vector* completed_tasks) { | 328 cc::DependencyTask::Vector* completed_tasks) { |
| 328 DCHECK(token.IsValid()); | 329 DCHECK(token.IsValid()); |
| 329 work_queue_.CollectCompletedTasks(token, completed_tasks); | 330 work_queue_.CollectCompletedTasks(token, completed_tasks); |
| 330 } | 331 } |
| 331 | 332 |
| 332 bool RasterWorkerPool::RunTaskWithLockAcquired( | 333 bool RasterWorkerPool::RunTaskWithLockAcquired( |
| 333 const std::vector<cc::TaskCategory>& categories) { | 334 const std::vector<cc::TaskCategory>& categories) { |
| 334 for (const auto& category : categories) { | 335 for (const auto& category : categories) { |
| 335 if (ShouldRunTaskForCategoryWithLockAcquired(category)) { | 336 if (ShouldRunTaskForCategoryWithLockAcquired(category)) { |
| 336 RunTaskInCategoryWithLockAcquired(category); | 337 RunTaskInCategoryWithLockAcquired(category); |
| 337 return true; | 338 return true; |
| 338 } | 339 } |
| 339 } | 340 } |
| 340 return false; | 341 return false; |
| 341 } | 342 } |
| 342 | 343 |
| 343 void RasterWorkerPool::RunTaskInCategoryWithLockAcquired( | 344 void RasterWorkerPool::RunTaskInCategoryWithLockAcquired( |
| 344 cc::TaskCategory category) { | 345 cc::TaskCategory category) { |
| 345 TRACE_EVENT0("toplevel", "TaskGraphRunner::RunTask"); | 346 TRACE_EVENT0("toplevel", "TaskGraphRunner::RunTask"); |
| 346 | 347 |
| 347 lock_.AssertAcquired(); | 348 lock_.AssertAcquired(); |
| 348 | 349 |
| 349 auto prioritized_task = work_queue_.GetNextTaskToRun(category); | 350 auto prioritized_task = work_queue_.GetNextTaskToRun(category); |
| 350 cc::Task* task = prioritized_task.task; | 351 cc::DependencyTask* task = prioritized_task.task; |
| 351 | 352 |
| 352 // There may be more work available, so wake up another worker thread. | 353 // There may be more work available, so wake up another worker thread. |
| 353 SignalHasReadyToRunTasksWithLockAcquired(); | 354 SignalHasReadyToRunTasksWithLockAcquired(); |
| 354 | 355 |
| 355 // Call WillRun() before releasing |lock_| and running task. | 356 // Call WillRun() before releasing |lock_| and running task. |
| 356 task->WillRun(); | 357 task->WillRun(); |
| 357 | 358 |
| 358 { | 359 { |
| 359 base::AutoUnlock unlock(lock_); | 360 base::AutoUnlock unlock(lock_); |
| 360 | 361 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 | 425 |
| 425 // Overridden from cc::Task: | 426 // Overridden from cc::Task: |
| 426 void RasterWorkerPool::ClosureTask::RunOnWorkerThread() { | 427 void RasterWorkerPool::ClosureTask::RunOnWorkerThread() { |
| 427 closure_.Run(); | 428 closure_.Run(); |
| 428 closure_.Reset(); | 429 closure_.Reset(); |
| 429 } | 430 } |
| 430 | 431 |
| 431 RasterWorkerPool::ClosureTask::~ClosureTask() {} | 432 RasterWorkerPool::ClosureTask::~ClosureTask() {} |
| 432 | 433 |
| 433 } // namespace content | 434 } // namespace content |
| OLD | NEW |