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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 // tasks. | 113 // tasks. |
114 cc::Task::Vector completed_tasks_; | 114 cc::Task::Vector completed_tasks_; |
115 }; | 115 }; |
116 | 116 |
117 RasterWorkerPool::RasterWorkerPool() | 117 RasterWorkerPool::RasterWorkerPool() |
118 : namespace_token_(GetNamespaceToken()), | 118 : namespace_token_(GetNamespaceToken()), |
119 has_ready_to_run_tasks_cv_(&lock_), | 119 has_ready_to_run_tasks_cv_(&lock_), |
120 has_namespaces_with_finished_running_tasks_cv_(&lock_), | 120 has_namespaces_with_finished_running_tasks_cv_(&lock_), |
121 shutdown_(false) {} | 121 shutdown_(false) {} |
122 | 122 |
123 void RasterWorkerPool::Start( | 123 void RasterWorkerPool::Start(int num_foreground_threads) { |
124 int num_threads, | |
125 const base::SimpleThread::Options& thread_options) { | |
126 DCHECK(threads_.empty()); | 124 DCHECK(threads_.empty()); |
127 while (threads_.size() < static_cast<size_t>(num_threads)) { | 125 |
128 // Determine the categories that each thread can run. | 126 while (threads_.size() < static_cast<size_t>(num_foreground_threads)) { |
127 // Determine the categories that each foreground thread can run. | |
129 std::vector<cc::TaskCategory> task_categories; | 128 std::vector<cc::TaskCategory> task_categories; |
130 | 129 |
131 // The first thread can run nonconcurrent tasks. | 130 // The first thread can run nonconcurrent tasks. |
132 if (threads_.size() == 0) { | 131 if (!threads_.size()) { |
133 task_categories.push_back(cc::TASK_CATEGORY_NONCONCURRENT_FOREGROUND); | 132 task_categories.push_back(cc::TASK_CATEGORY_NONCONCURRENT_FOREGROUND); |
134 } | 133 } |
135 | 134 |
136 // All threads can run foreground tasks. | 135 // All threads can run foreground tasks. |
137 task_categories.push_back(cc::TASK_CATEGORY_FOREGROUND); | 136 task_categories.push_back(cc::TASK_CATEGORY_FOREGROUND); |
138 | 137 |
139 // The last thread can run background tasks. | 138 scoped_ptr<base::SimpleThread> foreground_thread(new RasterWorkerPoolThread( |
140 if (threads_.size() == (static_cast<size_t>(num_threads) - 1)) { | |
141 task_categories.push_back(cc::TASK_CATEGORY_BACKGROUND); | |
142 } | |
143 | |
144 scoped_ptr<base::SimpleThread> thread(new RasterWorkerPoolThread( | |
145 base::StringPrintf("CompositorTileWorker%u", | 139 base::StringPrintf("CompositorTileWorker%u", |
146 static_cast<unsigned>(threads_.size() + 1)) | 140 static_cast<unsigned>(threads_.size() + 1)) |
147 .c_str(), | 141 .c_str(), |
148 thread_options, this, task_categories)); | 142 base::SimpleThread::Options(), this, task_categories)); |
149 thread->Start(); | 143 foreground_thread->Start(); |
150 threads_.push_back(std::move(thread)); | 144 threads_.push_back(std::move(foreground_thread)); |
151 } | 145 } |
146 | |
147 // Background thread can only run background tasks. | |
ericrk
2016/01/26 22:39:56
I like this idea in general, but a few questions:
| |
148 std::vector<cc::TaskCategory> background_task_categories; | |
149 background_task_categories.push_back(cc::TASK_CATEGORY_BACKGROUND); | |
150 | |
151 // Use background priority for background thread. | |
152 base::SimpleThread::Options thread_options; | |
153 thread_options.set_priority(base::ThreadPriority::BACKGROUND); | |
154 | |
155 scoped_ptr<base::SimpleThread> background_thread(new RasterWorkerPoolThread( | |
156 base::StringPrintf("CompositorTileWorker%u", | |
157 static_cast<unsigned>(threads_.size() + 1)) | |
158 .c_str(), | |
159 thread_options, this, background_task_categories)); | |
160 background_thread->Start(); | |
161 threads_.push_back(std::move(background_thread)); | |
152 } | 162 } |
153 | 163 |
154 void RasterWorkerPool::Shutdown() { | 164 void RasterWorkerPool::Shutdown() { |
155 WaitForTasksToFinishRunning(namespace_token_); | 165 WaitForTasksToFinishRunning(namespace_token_); |
156 CollectCompletedTasks(namespace_token_, &completed_tasks_); | 166 CollectCompletedTasks(namespace_token_, &completed_tasks_); |
157 // Shutdown raster threads. | 167 // Shutdown raster threads. |
158 { | 168 { |
159 base::AutoLock lock(lock_); | 169 base::AutoLock lock(lock_); |
160 | 170 |
161 DCHECK(!work_queue_.HasReadyToRunTasks()); | 171 DCHECK(!work_queue_.HasReadyToRunTasks()); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 | 366 |
357 // Overridden from cc::Task: | 367 // Overridden from cc::Task: |
358 void RasterWorkerPool::ClosureTask::RunOnWorkerThread() { | 368 void RasterWorkerPool::ClosureTask::RunOnWorkerThread() { |
359 closure_.Run(); | 369 closure_.Run(); |
360 closure_.Reset(); | 370 closure_.Reset(); |
361 } | 371 } |
362 | 372 |
363 RasterWorkerPool::ClosureTask::~ClosureTask() {} | 373 RasterWorkerPool::ClosureTask::~ClosureTask() {} |
364 | 374 |
365 } // namespace content | 375 } // namespace content |
OLD | NEW |