Commit 7bc54ba8 authored by ulan's avatar ulan Committed by Commit bot

Check number of finished tasks in PageParallelJob.

BUG=chromium:609249
LOG=NO

Review-Url: https://codereview.chromium.org/1976133002
Cr-Commit-Position: refs/heads/master@{#36238}
parent 72b510df
...@@ -39,7 +39,8 @@ class PageParallelJob { ...@@ -39,7 +39,8 @@ class PageParallelJob {
items_(nullptr), items_(nullptr),
num_items_(0), num_items_(0),
num_tasks_(0), num_tasks_(0),
pending_tasks_(new base::Semaphore(0)) {} pending_tasks_(new base::Semaphore(0)),
finished_tasks_(new base::AtomicNumber<int>(0)) {}
~PageParallelJob() { ~PageParallelJob() {
Item* item = items_; Item* item = items_;
...@@ -49,6 +50,7 @@ class PageParallelJob { ...@@ -49,6 +50,7 @@ class PageParallelJob {
item = next; item = next;
} }
delete pending_tasks_; delete pending_tasks_;
delete finished_tasks_;
} }
void AddPage(MemoryChunk* chunk, typename JobTraits::PerPageData data) { void AddPage(MemoryChunk* chunk, typename JobTraits::PerPageData data) {
...@@ -83,7 +85,7 @@ class PageParallelJob { ...@@ -83,7 +85,7 @@ class PageParallelJob {
start_index -= num_items_; start_index -= num_items_;
} }
Task* task = new Task(heap_, items_, num_items_, start_index, Task* task = new Task(heap_, items_, num_items_, start_index,
pending_tasks_, per_task_data_callback(i)); pending_tasks_, per_task_data_callback(i), this);
task_ids[i] = task->id(); task_ids[i] = task->id();
if (i > 0) { if (i > 0) {
V8::GetCurrentPlatform()->CallOnBackgroundThread( V8::GetCurrentPlatform()->CallOnBackgroundThread(
...@@ -95,12 +97,18 @@ class PageParallelJob { ...@@ -95,12 +97,18 @@ class PageParallelJob {
// Contribute on main thread. // Contribute on main thread.
main_task->Run(); main_task->Run();
delete main_task; delete main_task;
int aborted_tasks = 0;
// Wait for background tasks. // Wait for background tasks.
for (int i = 0; i < num_tasks_; i++) { for (int i = 0; i < num_tasks_; i++) {
if (!cancelable_task_manager_->TryAbort(task_ids[i])) { if (!cancelable_task_manager_->TryAbort(task_ids[i])) {
pending_tasks_->Wait(); pending_tasks_->Wait();
} else {
++aborted_tasks;
} }
} }
int finished_tasks = finished_tasks_->Value();
// TODO(ulan): Remove this check after investigation of crbug.com/609249.
CHECK_EQ(aborted_tasks + finished_tasks, num_tasks_);
if (JobTraits::NeedSequentialFinalization) { if (JobTraits::NeedSequentialFinalization) {
Item* item = items_; Item* item = items_;
while (item != nullptr) { while (item != nullptr) {
...@@ -112,6 +120,8 @@ class PageParallelJob { ...@@ -112,6 +120,8 @@ class PageParallelJob {
} }
} }
void NotifyFinishedTask() { finished_tasks_->Increment(1); }
private: private:
static const int kMaxNumberOfTasks = 10; static const int kMaxNumberOfTasks = 10;
...@@ -129,14 +139,16 @@ class PageParallelJob { ...@@ -129,14 +139,16 @@ class PageParallelJob {
class Task : public CancelableTask { class Task : public CancelableTask {
public: public:
Task(Heap* heap, Item* items, int num_items, int start_index, Task(Heap* heap, Item* items, int num_items, int start_index,
base::Semaphore* on_finish, typename JobTraits::PerTaskData data) base::Semaphore* on_finish, typename JobTraits::PerTaskData data,
PageParallelJob<JobTraits>* job)
: CancelableTask(heap->isolate()), : CancelableTask(heap->isolate()),
heap_(heap), heap_(heap),
items_(items), items_(items),
num_items_(num_items), num_items_(num_items),
start_index_(start_index), start_index_(start_index),
on_finish_(on_finish), on_finish_(on_finish),
data_(data) {} data_(data),
job_(job) {}
virtual ~Task() {} virtual ~Task() {}
...@@ -161,6 +173,7 @@ class PageParallelJob { ...@@ -161,6 +173,7 @@ class PageParallelJob {
current = items_; current = items_;
} }
} }
job_->NotifyFinishedTask();
on_finish_->Signal("PageParallelJob::Task::RunInternal"); on_finish_->Signal("PageParallelJob::Task::RunInternal");
} }
...@@ -170,6 +183,7 @@ class PageParallelJob { ...@@ -170,6 +183,7 @@ class PageParallelJob {
int start_index_; int start_index_;
base::Semaphore* on_finish_; base::Semaphore* on_finish_;
typename JobTraits::PerTaskData data_; typename JobTraits::PerTaskData data_;
PageParallelJob<JobTraits>* job_;
DISALLOW_COPY_AND_ASSIGN(Task); DISALLOW_COPY_AND_ASSIGN(Task);
}; };
...@@ -179,6 +193,7 @@ class PageParallelJob { ...@@ -179,6 +193,7 @@ class PageParallelJob {
int num_items_; int num_items_;
int num_tasks_; int num_tasks_;
base::Semaphore* pending_tasks_; base::Semaphore* pending_tasks_;
base::AtomicNumber<int>* finished_tasks_;
DISALLOW_COPY_AND_ASSIGN(PageParallelJob); DISALLOW_COPY_AND_ASSIGN(PageParallelJob);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment