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