Chromium Code Reviews| Index: cc/raster_worker_pool.cc |
| diff --git a/cc/raster_worker_pool.cc b/cc/raster_worker_pool.cc |
| index cc10956af08b8654de5410b075d44a1a3cfbbd58..8eb92c209da3d368877d8bd47222ebf6c7b56948 100644 |
| --- a/cc/raster_worker_pool.cc |
| +++ b/cc/raster_worker_pool.cc |
| @@ -75,11 +75,11 @@ RasterWorkerPool::Thread::Task::~Task() { |
| RasterWorkerPool::Thread::Thread(const std::string name) |
| : base::Thread(name.c_str()), |
| num_pending_tasks_(0) { |
| - Start(); |
| } |
| RasterWorkerPool::Thread::~Thread() { |
| Stop(); |
| + DCHECK_EQ(num_pending_tasks_, 0); |
| } |
| void RasterWorkerPool::Thread::Init() { |
| @@ -90,7 +90,9 @@ void RasterWorkerPool::Thread::Init() { |
| #endif |
| } |
| -RasterWorkerPool::RasterWorkerPool(size_t num_raster_threads) { |
| +RasterWorkerPool::RasterWorkerPool(size_t num_raster_threads) |
| + : is_running_(false), |
| + raster_threads_need_sorting_(false) { |
| const std::string thread_name_prefix = kRasterThreadNamePrefix; |
| while (raster_threads_.size() < num_raster_threads) { |
| int thread_number = raster_threads_.size() + 1; |
| @@ -101,10 +103,39 @@ RasterWorkerPool::RasterWorkerPool(size_t num_raster_threads) { |
| } |
| RasterWorkerPool::~RasterWorkerPool() { |
| + Stop(); |
| STLDeleteElements(&raster_threads_); |
| } |
| +bool RasterWorkerPool::Start() { |
| + for (ThreadVector::iterator it = raster_threads_.begin(); |
| + it != raster_threads_.end(); it++) { |
| + Thread* thread = *it; |
| + if (!thread->Start()) |
| + return false; |
| + } |
| + |
| + is_running_ = true; |
| + return true; |
| +} |
| + |
| +void RasterWorkerPool::Stop() { |
| + if (!is_running_) |
| + return; |
| + |
| + for (ThreadVector::iterator it = raster_threads_.begin(); |
| + it != raster_threads_.end(); it++) { |
| + Thread* thread = *it; |
| + thread->Stop(); |
| + } |
| + |
| + is_running_ = false; |
| +} |
| + |
| bool RasterWorkerPool::IsBusy() { |
| + DCHECK(is_running_); |
| + SortRasterThreadsIfNeeded(); |
| + |
| Thread* thread = raster_threads_.front(); |
| return thread->num_pending_tasks() >= kNumPendingRasterTasksPerThread; |
| } |
| @@ -114,6 +145,7 @@ void RasterWorkerPool::PostRasterTaskAndReply(PicturePileImpl* picture_pile, |
| const gfx::Rect& rect, |
| float contents_scale, |
| const base::Closure& reply) { |
| + CHECK(is_running_); |
| Thread::Task* task = CreateTask(); |
| scoped_refptr<PicturePileImpl> picture_pile_clone = |
| @@ -137,6 +169,7 @@ void RasterWorkerPool::PostRasterTaskAndReply(PicturePileImpl* picture_pile, |
| void RasterWorkerPool::PostImageDecodeTaskAndReply( |
| skia::LazyPixelRef* pixel_ref, |
| const base::Closure& reply) { |
| + CHECK(is_running_); |
| Thread::Task* task = CreateTask(); |
| task->thread_->message_loop_proxy()->PostTaskAndReply( |
| @@ -172,15 +205,13 @@ RasterWorkerPool::Thread::Task* RasterWorkerPool::CreateTask() { |
| DCHECK(thread->num_pending_tasks() < kNumPendingRasterTasksPerThread); |
| scoped_ptr<Thread::Task> task(new Thread::Task(thread)); |
| - std::sort(raster_threads_.begin(), raster_threads_.end(), |
| - PendingTaskComparator()); |
| + raster_threads_need_sorting_ = true; |
| return task.release(); |
| } |
| void RasterWorkerPool::DestroyTask(Thread::Task* task) { |
| delete task; |
| - std::sort(raster_threads_.begin(), raster_threads_.end(), |
| - PendingTaskComparator()); |
| + raster_threads_need_sorting_ = true; |
| } |
| void RasterWorkerPool::OnTaskCompleted( |
| @@ -196,4 +227,13 @@ void RasterWorkerPool::OnRasterTaskCompleted( |
| OnTaskCompleted(task, reply); |
| } |
| +void RasterWorkerPool::SortRasterThreadsIfNeeded() { |
| + if (!raster_threads_need_sorting_) |
|
nduca
2013/01/29 00:13:08
Out of curiosity, what does this do?
reveman
2013/01/29 02:49:54
Rather than having iterate over all threads both w
|
| + return; |
| + |
| + std::sort(raster_threads_.begin(), raster_threads_.end(), |
| + PendingTaskComparator()); |
| + raster_threads_need_sorting_ = false; |
| +} |
| + |
| } // namespace cc |