summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authorvmpstr@chromium.org <vmpstr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-26 04:23:45 +0000
committervmpstr@chromium.org <vmpstr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-26 04:23:45 +0000
commit0baa4a1cf74c5e4817f3a80fb5a624f0c7187d6c (patch)
treefd1343f491bfcd0d4218c1d583f3b6c6846b80c5 /cc
parente86d2f32bd47a097d15ff8be5059cefddf4887d7 (diff)
downloadchromium_src-0baa4a1cf74c5e4817f3a80fb5a624f0c7187d6c.zip
chromium_src-0baa4a1cf74c5e4817f3a80fb5a624f0c7187d6c.tar.gz
chromium_src-0baa4a1cf74c5e4817f3a80fb5a624f0c7187d6c.tar.bz2
cc: Use a vector for completed tasks
Instead of using a deque, this patch uses a vector for completed tasks. BUG=253971 Review URL: https://chromiumcodereview.appspot.com/17587019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208624 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/resources/image_raster_worker_pool.cc9
-rw-r--r--cc/resources/pixel_buffer_raster_worker_pool.cc9
-rw-r--r--cc/resources/raster_worker_pool.cc19
-rw-r--r--cc/resources/raster_worker_pool.h5
-rw-r--r--cc/resources/raster_worker_pool_perftest.cc4
-rw-r--r--cc/resources/raster_worker_pool_unittest.cc5
-rw-r--r--cc/resources/worker_pool.cc34
-rw-r--r--cc/resources/worker_pool.h9
-rw-r--r--cc/resources/worker_pool_perftest.cc8
-rw-r--r--cc/resources/worker_pool_unittest.cc4
10 files changed, 61 insertions, 45 deletions
diff --git a/cc/resources/image_raster_worker_pool.cc b/cc/resources/image_raster_worker_pool.cc
index c2fe395..1d96b27 100644
--- a/cc/resources/image_raster_worker_pool.cc
+++ b/cc/resources/image_raster_worker_pool.cc
@@ -27,7 +27,7 @@ class ImageWorkerPoolTaskImpl : public internal::WorkerPoolTask {
}
// Overridden from internal::WorkerPoolTask:
- virtual void RunOnThread(unsigned thread_index) OVERRIDE {
+ virtual void RunOnWorkerThread(unsigned thread_index) OVERRIDE {
if (!buffer_)
return;
@@ -38,9 +38,9 @@ class ImageWorkerPoolTaskImpl : public internal::WorkerPoolTask {
stride_);
bitmap.setPixels(buffer_);
SkDevice device(bitmap);
- task_->RunOnThread(&device, thread_index);
+ task_->RunOnWorkerThread(&device, thread_index);
}
- virtual void DispatchCompletionCallback() OVERRIDE {
+ virtual void CompleteOnOriginThread() OVERRIDE {
reply_.Run(!HasFinishedRunning());
}
@@ -120,8 +120,9 @@ void ImageRasterWorkerPool::OnRasterTaskCompleted(
resource_provider()->BindImage(task->resource()->id());
task->DidRun(was_canceled);
+ task->WillComplete();
+ task->CompleteOnOriginThread();
task->DidComplete();
- task->DispatchCompletionCallback();
image_tasks_.erase(task.get());
}
diff --git a/cc/resources/pixel_buffer_raster_worker_pool.cc b/cc/resources/pixel_buffer_raster_worker_pool.cc
index 488b5ac..14a2536 100644
--- a/cc/resources/pixel_buffer_raster_worker_pool.cc
+++ b/cc/resources/pixel_buffer_raster_worker_pool.cc
@@ -26,7 +26,7 @@ class PixelBufferWorkerPoolTaskImpl : public internal::WorkerPoolTask {
}
// Overridden from internal::WorkerPoolTask:
- virtual void RunOnThread(unsigned thread_index) OVERRIDE {
+ virtual void RunOnWorkerThread(unsigned thread_index) OVERRIDE {
// |buffer_| can be NULL in lost context situations.
if (!buffer_) {
// |needs_upload_| still needs to be true as task has not
@@ -40,9 +40,9 @@ class PixelBufferWorkerPoolTaskImpl : public internal::WorkerPoolTask {
task_->resource()->size().height());
bitmap.setPixels(buffer_);
SkDevice device(bitmap);
- needs_upload_ = task_->RunOnThread(&device, thread_index);
+ needs_upload_ = task_->RunOnWorkerThread(&device, thread_index);
}
- virtual void DispatchCompletionCallback() OVERRIDE {
+ virtual void CompleteOnOriginThread() OVERRIDE {
// |needs_upload_| must be be false if task didn't run.
DCHECK(HasFinishedRunning() || !needs_upload_);
reply_.Run(!HasFinishedRunning(), needs_upload_);
@@ -182,8 +182,9 @@ void PixelBufferRasterWorkerPool::CheckForCompletedTasks() {
pixel_buffer_tasks_.erase(task);
+ task->WillComplete();
+ task->CompleteOnOriginThread();
task->DidComplete();
- task->DispatchCompletionCallback();
completed_tasks_.pop_front();
}
diff --git a/cc/resources/raster_worker_pool.cc b/cc/resources/raster_worker_pool.cc
index 5f356e5..35f90a8 100644
--- a/cc/resources/raster_worker_pool.cc
+++ b/cc/resources/raster_worker_pool.cc
@@ -138,11 +138,12 @@ class RasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask {
}
// Overridden from internal::RasterWorkerPoolTask:
- virtual bool RunOnThread(SkDevice* device, unsigned thread_index) OVERRIDE {
+ virtual bool RunOnWorkerThread(SkDevice* device, unsigned thread_index)
+ OVERRIDE {
RunAnalysisOnThread(thread_index);
return RunRasterOnThread(device, thread_index);
}
- virtual void DispatchCompletionCallback() OVERRIDE {
+ virtual void CompleteOnOriginThread() OVERRIDE {
reply_.Run(analysis_, !HasFinishedRunning() || WasCanceled());
}
@@ -175,8 +176,8 @@ class ImageDecodeWorkerPoolTaskImpl : public internal::WorkerPoolTask {
reply_(reply) {}
// Overridden from internal::WorkerPoolTask:
- virtual void RunOnThread(unsigned thread_index) OVERRIDE {
- TRACE_EVENT0("cc", "ImageDecodeWorkerPoolTaskImpl::RunOnThread");
+ virtual void RunOnWorkerThread(unsigned thread_index) OVERRIDE {
+ TRACE_EVENT0("cc", "ImageDecodeWorkerPoolTaskImpl::RunOnWorkerThread");
devtools_instrumentation::ScopedLayerTask image_decode_task(
devtools_instrumentation::kImageDecodeTask, layer_id_);
base::TimeTicks start_time = rendering_stats_->StartRecording();
@@ -184,7 +185,7 @@ class ImageDecodeWorkerPoolTaskImpl : public internal::WorkerPoolTask {
base::TimeDelta duration = rendering_stats_->EndRecording(start_time);
rendering_stats_->AddDeferredImageDecode(duration);
}
- virtual void DispatchCompletionCallback() OVERRIDE {
+ virtual void CompleteOnOriginThread() OVERRIDE {
reply_.Run(!HasFinishedRunning());
}
@@ -210,10 +211,10 @@ class RasterFinishedWorkerPoolTaskImpl : public internal::WorkerPoolTask {
}
// Overridden from internal::WorkerPoolTask:
- virtual void RunOnThread(unsigned thread_index) OVERRIDE {
+ virtual void RunOnWorkerThread(unsigned thread_index) OVERRIDE {
origin_loop_->PostTask(FROM_HERE, on_raster_finished_callback_);
}
- virtual void DispatchCompletionCallback() OVERRIDE {}
+ virtual void CompleteOnOriginThread() OVERRIDE {}
private:
virtual ~RasterFinishedWorkerPoolTaskImpl() {}
@@ -258,6 +259,10 @@ bool RasterWorkerPoolTask::WasCanceled() const {
return was_canceled_;
}
+void RasterWorkerPoolTask::WillComplete() {
+ DCHECK(!did_complete_);
+}
+
void RasterWorkerPoolTask::DidComplete() {
DCHECK(!did_complete_);
did_complete_ = true;
diff --git a/cc/resources/raster_worker_pool.h b/cc/resources/raster_worker_pool.h
index c868be7..e6e777c 100644
--- a/cc/resources/raster_worker_pool.h
+++ b/cc/resources/raster_worker_pool.h
@@ -35,12 +35,13 @@ class CC_EXPORT RasterWorkerPoolTask
// Returns true if |device| was written to. False indicate that
// the content of |device| is undefined and the resource doesn't
// need to be initialized.
- virtual bool RunOnThread(SkDevice* device, unsigned thread_index) = 0;
- virtual void DispatchCompletionCallback() = 0;
+ virtual bool RunOnWorkerThread(SkDevice* device, unsigned thread_index) = 0;
+ virtual void CompleteOnOriginThread() = 0;
void DidRun(bool was_canceled);
bool HasFinishedRunning() const;
bool WasCanceled() const;
+ void WillComplete();
void DidComplete();
bool HasCompleted() const;
diff --git a/cc/resources/raster_worker_pool_perftest.cc b/cc/resources/raster_worker_pool_perftest.cc
index 44cc2c9..866daa8 100644
--- a/cc/resources/raster_worker_pool_perftest.cc
+++ b/cc/resources/raster_worker_pool_perftest.cc
@@ -18,8 +18,8 @@ static const int kTimeCheckInterval = 10;
class PerfWorkerPoolTaskImpl : public internal::WorkerPoolTask {
public:
// Overridden from internal::WorkerPoolTask:
- virtual void RunOnThread(unsigned thread_index) OVERRIDE {}
- virtual void DispatchCompletionCallback() OVERRIDE {}
+ virtual void RunOnWorkerThread(unsigned thread_index) OVERRIDE {}
+ virtual void CompleteOnOriginThread() OVERRIDE {}
private:
virtual ~PerfWorkerPoolTaskImpl() {}
diff --git a/cc/resources/raster_worker_pool_unittest.cc b/cc/resources/raster_worker_pool_unittest.cc
index ed98e48..7b82b3f 100644
--- a/cc/resources/raster_worker_pool_unittest.cc
+++ b/cc/resources/raster_worker_pool_unittest.cc
@@ -32,11 +32,12 @@ class TestRasterWorkerPoolTaskImpl : public internal::RasterWorkerPoolTask {
did_raster_(false) {}
// Overridden from internal::WorkerPoolTask:
- virtual bool RunOnThread(SkDevice* device, unsigned thread_index) OVERRIDE {
+ virtual bool RunOnWorkerThread(SkDevice* device, unsigned thread_index)
+ OVERRIDE {
did_raster_ = true;
return true;
}
- virtual void DispatchCompletionCallback() OVERRIDE {
+ virtual void CompleteOnOriginThread() OVERRIDE {
reply_.Run(PicturePileImpl::Analysis(), !HasFinishedRunning(), did_raster_);
}
diff --git a/cc/resources/worker_pool.cc b/cc/resources/worker_pool.cc
index a1d64a3..90e3032 100644
--- a/cc/resources/worker_pool.cc
+++ b/cc/resources/worker_pool.cc
@@ -51,6 +51,10 @@ void WorkerPoolTask::DidRun() {
did_run_ = true;
}
+void WorkerPoolTask::WillComplete() {
+ DCHECK(!did_complete_);
+}
+
void WorkerPoolTask::DidComplete() {
DCHECK(did_schedule_);
DCHECK(!did_complete_);
@@ -86,7 +90,7 @@ class WorkerPool::Inner : public base::DelegateSimpleThread::Delegate {
void SetTaskGraph(TaskGraph* graph);
// Collect all completed tasks in |completed_tasks|.
- void CollectCompletedTasks(TaskDeque* completed_tasks);
+ void CollectCompletedTasks(TaskVector* completed_tasks);
private:
class PriorityComparator {
@@ -131,7 +135,7 @@ class WorkerPool::Inner : public base::DelegateSimpleThread::Delegate {
GraphNodeMap running_tasks_;
// Completed tasks not yet collected by origin thread.
- TaskDeque completed_tasks_;
+ TaskVector completed_tasks_;
ScopedPtrDeque<base::DelegateSimpleThread> workers_;
@@ -206,7 +210,7 @@ void WorkerPool::Inner::SetTaskGraph(TaskGraph* graph) {
// First remove all completed tasks from |new_pending_tasks| and
// adjust number of dependencies.
- for (TaskDeque::iterator it = completed_tasks_.begin();
+ for (TaskVector::iterator it = completed_tasks_.begin();
it != completed_tasks_.end(); ++it) {
internal::WorkerPoolTask* task = it->get();
@@ -277,7 +281,7 @@ void WorkerPool::Inner::SetTaskGraph(TaskGraph* graph) {
}
}
-void WorkerPool::Inner::CollectCompletedTasks(TaskDeque* completed_tasks) {
+void WorkerPool::Inner::CollectCompletedTasks(TaskVector* completed_tasks) {
base::AutoLock lock(lock_);
DCHECK_EQ(0u, completed_tasks->size());
@@ -326,7 +330,7 @@ void WorkerPool::Inner::Run() {
{
base::AutoUnlock unlock(lock_);
- task->RunOnThread(thread_index);
+ task->RunOnWorkerThread(thread_index);
}
// This will mark task as finished running.
@@ -390,24 +394,26 @@ void WorkerPool::CheckForCompletedTasks() {
DCHECK(!in_dispatch_completion_callbacks_);
- TaskDeque completed_tasks;
+ TaskVector completed_tasks;
inner_->CollectCompletedTasks(&completed_tasks);
- DispatchCompletionCallbacks(&completed_tasks);
+ ProcessCompletedTasks(completed_tasks);
}
-void WorkerPool::DispatchCompletionCallbacks(TaskDeque* completed_tasks) {
- TRACE_EVENT0("cc", "WorkerPool::DispatchCompletionCallbacks");
+void WorkerPool::ProcessCompletedTasks(
+ const TaskVector& completed_tasks) {
+ TRACE_EVENT0("cc", "WorkerPool::ProcessCompletedTasks");
// Worker pool instance is not reentrant while processing completed tasks.
in_dispatch_completion_callbacks_ = true;
- while (!completed_tasks->empty()) {
- internal::WorkerPoolTask* task = completed_tasks->front().get();
+ for (TaskVector::const_iterator it = completed_tasks.begin();
+ it != completed_tasks.end();
+ ++it) {
+ internal::WorkerPoolTask* task = it->get();
+ task->WillComplete();
+ task->CompleteOnOriginThread();
task->DidComplete();
- task->DispatchCompletionCallback();
-
- completed_tasks->pop_front();
}
in_dispatch_completion_callbacks_ = false;
diff --git a/cc/resources/worker_pool.h b/cc/resources/worker_pool.h
index a8f27db..57bc774 100644
--- a/cc/resources/worker_pool.h
+++ b/cc/resources/worker_pool.h
@@ -23,12 +23,13 @@ namespace internal {
class CC_EXPORT WorkerPoolTask
: public base::RefCountedThreadSafe<WorkerPoolTask> {
public:
- virtual void RunOnThread(unsigned thread_index) = 0;
- virtual void DispatchCompletionCallback() = 0;
+ virtual void RunOnWorkerThread(unsigned thread_index) = 0;
+ virtual void CompleteOnOriginThread() = 0;
void DidSchedule();
void WillRun();
void DidRun();
+ void WillComplete();
void DidComplete();
bool HasFinishedRunning() const;
@@ -131,9 +132,9 @@ class CC_EXPORT WorkerPool {
class Inner;
friend class Inner;
- typedef std::deque<scoped_refptr<internal::WorkerPoolTask> > TaskDeque;
+ typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector;
- void DispatchCompletionCallbacks(TaskDeque* completed_tasks);
+ void ProcessCompletedTasks(const TaskVector& completed_tasks);
bool in_dispatch_completion_callbacks_;
diff --git a/cc/resources/worker_pool_perftest.cc b/cc/resources/worker_pool_perftest.cc
index b7a1c4c..c32a59b 100644
--- a/cc/resources/worker_pool_perftest.cc
+++ b/cc/resources/worker_pool_perftest.cc
@@ -19,8 +19,8 @@ static const int kTimeCheckInterval = 10;
class PerfWorkerPoolTaskImpl : public internal::WorkerPoolTask {
public:
// Overridden from internal::WorkerPoolTask:
- virtual void RunOnThread(unsigned thread_index) OVERRIDE {}
- virtual void DispatchCompletionCallback() OVERRIDE {}
+ virtual void RunOnWorkerThread(unsigned thread_index) OVERRIDE {}
+ virtual void CompleteOnOriginThread() OVERRIDE {}
private:
virtual ~PerfWorkerPoolTaskImpl() {}
@@ -32,11 +32,11 @@ class PerfControlWorkerPoolTaskImpl : public internal::WorkerPoolTask {
can_finish_(new CompletionEvent) {}
// Overridden from internal::WorkerPoolTask:
- virtual void RunOnThread(unsigned thread_index) OVERRIDE {
+ virtual void RunOnWorkerThread(unsigned thread_index) OVERRIDE {
did_start_->Signal();
can_finish_->Wait();
}
- virtual void DispatchCompletionCallback() OVERRIDE {}
+ virtual void CompleteOnOriginThread() OVERRIDE {}
void WaitForTaskToStartRunning() {
did_start_->Wait();
diff --git a/cc/resources/worker_pool_unittest.cc b/cc/resources/worker_pool_unittest.cc
index 5c946e0..f137155 100644
--- a/cc/resources/worker_pool_unittest.cc
+++ b/cc/resources/worker_pool_unittest.cc
@@ -22,11 +22,11 @@ class FakeWorkerPoolTaskImpl : public internal::WorkerPoolTask {
}
// Overridden from internal::WorkerPoolTask:
- virtual void RunOnThread(unsigned thread_index) OVERRIDE {
+ virtual void RunOnWorkerThread(unsigned thread_index) OVERRIDE {
if (!callback_.is_null())
callback_.Run();
}
- virtual void DispatchCompletionCallback() OVERRIDE {
+ virtual void CompleteOnOriginThread() OVERRIDE {
if (!reply_.is_null())
reply_.Run();
}