Chromium Code Reviews| Index: cc/worker_pool.cc |
| diff --git a/cc/worker_pool.cc b/cc/worker_pool.cc |
| index 7d3428aa74d2f8bde286b73cb418549fb1504a70..c1a70ce8a655821a20eed4ae708e79a5f0a84269 100644 |
| --- a/cc/worker_pool.cc |
| +++ b/cc/worker_pool.cc |
| @@ -28,6 +28,7 @@ class WorkerPoolTaskImpl : public internal::WorkerPoolTask { |
| virtual void Run(RenderingStats* rendering_stats) OVERRIDE { |
| task_.Run(rendering_stats); |
| + base::subtle::NoBarrier_Store(&completed_, 1); |
|
brianderson
2013/02/12 01:44:31
I think you need a barrier before this store (or a
reveman
2013/02/12 02:29:52
Done.
|
| } |
| private: |
| @@ -36,22 +37,24 @@ class WorkerPoolTaskImpl : public internal::WorkerPoolTask { |
| const char* kWorkerThreadNamePrefix = "Compositor"; |
| -// Allow two pending tasks per worker. This keeps resource usage |
| -// low while making sure workers aren't unnecessarily idle. |
| -const int kNumPendingTasksPerWorker = 2; |
| - |
| } // namespace |
| namespace internal { |
| WorkerPoolTask::WorkerPoolTask(const base::Closure& reply) |
| : reply_(reply) { |
| + base::subtle::NoBarrier_Store(&completed_, 0); |
|
brianderson
2013/02/12 01:44:31
I think you need a barrier after this store (or an
reveman
2013/02/12 02:29:52
Done.
|
| } |
| WorkerPoolTask::~WorkerPoolTask() { |
| } |
| +bool WorkerPoolTask::IsPending() { |
| + return base::subtle::NoBarrier_Load(&completed_) == 0; |
| +} |
| + |
| void WorkerPoolTask::Completed() { |
| + DCHECK_EQ(base::subtle::NoBarrier_Load(&completed_), 1); |
| reply_.Run(); |
| } |
| @@ -60,7 +63,6 @@ void WorkerPoolTask::Completed() { |
| WorkerPool::Worker::Worker(WorkerPool* worker_pool, const std::string name) |
| : base::Thread(name.c_str()), |
| worker_pool_(worker_pool), |
| - weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| rendering_stats_(make_scoped_ptr(new RenderingStats)), |
| record_rendering_stats_(false) { |
| Start(); |
| @@ -80,23 +82,17 @@ void WorkerPool::Worker::StopAfterCompletingAllPendingTasks() { |
| // all tasks have finished running. |
| while (!pending_tasks_.empty()) |
| OnTaskCompleted(); |
| - |
| - // Cancel all pending replies. |
| - weak_ptr_factory_.InvalidateWeakPtrs(); |
| } |
| void WorkerPool::Worker::PostTask(scoped_ptr<internal::WorkerPoolTask> task) { |
| - DCHECK_LT(num_pending_tasks(), kNumPendingTasksPerWorker); |
| - |
| RenderingStats* stats = |
| record_rendering_stats_ ? rendering_stats_.get() : NULL; |
| - message_loop_proxy()->PostTaskAndReply( |
| + message_loop_proxy()->PostTask( |
| FROM_HERE, |
| base::Bind(&Worker::RunTask, |
| base::Unretained(task.get()), |
| - base::Unretained(stats)), |
| - base::Bind(&Worker::OnTaskCompleted, weak_ptr_factory_.GetWeakPtr())); |
| + base::Unretained(stats))); |
| pending_tasks_.push_back(task.Pass()); |
| @@ -126,6 +122,15 @@ void WorkerPool::Worker::OnTaskCompleted() { |
| worker_pool_->DidNumPendingTasksChange(); |
| } |
| +void WorkerPool::Worker::CheckForCompletedTasks() { |
| + while (!pending_tasks_.empty()) { |
| + if (pending_tasks_.front()->IsPending()) |
| + return; |
| + |
| + OnTaskCompleted(); |
| + } |
| +} |
| + |
| WorkerPool::WorkerPool(size_t num_threads) |
| : workers_need_sorting_(false), |
| shutdown_(false) { |
| @@ -164,10 +169,12 @@ void WorkerPool::PostTaskAndReply( |
| reply)).PassAs<internal::WorkerPoolTask>()); |
| } |
| -bool WorkerPool::IsBusy() { |
| - Worker* worker = GetWorkerForNextTask(); |
| - |
| - return worker->num_pending_tasks() >= kNumPendingTasksPerWorker; |
| +void WorkerPool::CheckForCompletedTasks() { |
| + for (WorkerVector::iterator it = workers_.begin(); |
| + it != workers_.end(); it++) { |
| + Worker* worker = *it; |
| + worker->CheckForCompletedTasks(); |
| + } |
| } |
| void WorkerPool::SetRecordRenderingStats(bool record_rendering_stats) { |