OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/base/worker_pool.h" | 5 #include "cc/base/worker_pool.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 next_thread_index_(0), | 170 next_thread_index_(0), |
171 running_task_count_(0), | 171 running_task_count_(0), |
172 shutdown_(false) { | 172 shutdown_(false) { |
173 base::AutoLock lock(lock_); | 173 base::AutoLock lock(lock_); |
174 | 174 |
175 while (workers_.size() < num_threads) { | 175 while (workers_.size() < num_threads) { |
176 scoped_ptr<base::DelegateSimpleThread> worker = make_scoped_ptr( | 176 scoped_ptr<base::DelegateSimpleThread> worker = make_scoped_ptr( |
177 new base::DelegateSimpleThread( | 177 new base::DelegateSimpleThread( |
178 this, | 178 this, |
179 thread_name_prefix + | 179 thread_name_prefix + |
180 base::StringPrintf( | 180 base::StringPrintf("Worker%lu", workers_.size() + 1).c_str())); |
181 "Worker%lu", | |
182 static_cast<unsigned long>(workers_.size() + 1)).c_str())); | |
183 worker->Start(); | 181 worker->Start(); |
184 workers_.push_back(worker.Pass()); | 182 workers_.push_back(worker.Pass()); |
185 } | 183 } |
186 } | 184 } |
187 | 185 |
188 WorkerPool::Inner::~Inner() { | 186 WorkerPool::Inner::~Inner() { |
189 base::AutoLock lock(lock_); | 187 base::AutoLock lock(lock_); |
190 | 188 |
191 DCHECK(shutdown_); | 189 DCHECK(shutdown_); |
192 | 190 |
193 // Cancel all pending callbacks. | 191 // Cancel all pending callbacks. |
194 weak_ptr_factory_.InvalidateWeakPtrs(); | 192 weak_ptr_factory_.InvalidateWeakPtrs(); |
195 | 193 |
196 DCHECK_EQ(0u, pending_tasks_.size()); | 194 DCHECK_EQ(pending_tasks_.size(), 0); |
197 DCHECK_EQ(0u, completed_tasks_.size()); | 195 DCHECK_EQ(completed_tasks_.size(), 0); |
198 DCHECK_EQ(0u, running_task_count_); | 196 DCHECK_EQ(running_task_count_, 0); |
199 } | 197 } |
200 | 198 |
201 void WorkerPool::Inner::Shutdown() { | 199 void WorkerPool::Inner::Shutdown() { |
202 { | 200 { |
203 base::AutoLock lock(lock_); | 201 base::AutoLock lock(lock_); |
204 | 202 |
205 DCHECK(!shutdown_); | 203 DCHECK(!shutdown_); |
206 shutdown_ = true; | 204 shutdown_ = true; |
207 | 205 |
208 // Wake up a worker so it knows it should exit. This will cause all workers | 206 // Wake up a worker so it knows it should exit. This will cause all workers |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 // for completed tasks delay is 0. | 423 // for completed tasks delay is 0. |
426 check_for_completed_tasks_delay == base::TimeDelta()))) { | 424 check_for_completed_tasks_delay == base::TimeDelta()))) { |
427 } | 425 } |
428 | 426 |
429 WorkerPool::~WorkerPool() { | 427 WorkerPool::~WorkerPool() { |
430 Shutdown(); | 428 Shutdown(); |
431 | 429 |
432 // Cancel all pending callbacks. | 430 // Cancel all pending callbacks. |
433 weak_ptr_factory_.InvalidateWeakPtrs(); | 431 weak_ptr_factory_.InvalidateWeakPtrs(); |
434 | 432 |
435 DCHECK_EQ(0u, completed_tasks_.size()); | 433 DCHECK_EQ(completed_tasks_.size(), 0); |
436 } | 434 } |
437 | 435 |
438 void WorkerPool::Shutdown() { | 436 void WorkerPool::Shutdown() { |
439 inner_->Shutdown(); | 437 inner_->Shutdown(); |
440 DispatchCompletionCallbacks(); | 438 DispatchCompletionCallbacks(); |
441 } | 439 } |
442 | 440 |
443 void WorkerPool::PostTaskAndReply( | 441 void WorkerPool::PostTaskAndReply( |
444 const Callback& task, const base::Closure& reply) { | 442 const Callback& task, const base::Closure& reply) { |
445 PostTask(make_scoped_ptr(new WorkerPoolTaskImpl( | 443 PostTask(make_scoped_ptr(new WorkerPoolTaskImpl( |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 TRACE_EVENT_SCOPE_THREAD); | 564 TRACE_EVENT_SCOPE_THREAD); |
567 CancelCheckForCompletedTasks(); | 565 CancelCheckForCompletedTasks(); |
568 DispatchCompletionCallbacks(); | 566 DispatchCompletionCallbacks(); |
569 // Schedule another check for completed tasks if not idle. | 567 // Schedule another check for completed tasks if not idle. |
570 if (!is_idle) | 568 if (!is_idle) |
571 ScheduleCheckForCompletedTasks(); | 569 ScheduleCheckForCompletedTasks(); |
572 } | 570 } |
573 } | 571 } |
574 | 572 |
575 } // namespace cc | 573 } // namespace cc |
OLD | NEW |