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 {
items_(nullptr),
num_items_(0),
num_tasks_(0),
pending_tasks_(new base::Semaphore(0)) {}
pending_tasks_(new base::Semaphore(0)),
finished_tasks_(new base::AtomicNumber<int>(0)) {}
~PageParallelJob() {
Item* item = items_;
......@@ -49,6 +50,7 @@ class PageParallelJob {
item = next;
}
delete pending_tasks_;
delete finished_tasks_;
}
void AddPage(MemoryChunk* chunk, typename JobTraits::PerPageData data) {
......@@ -83,7 +85,7 @@ class PageParallelJob {
start_index -= num_items_;
}
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();
if (i > 0) {
V8::GetCurrentPlatform()->CallOnBackgroundThread(
......@@ -95,12 +97,18 @@ class PageParallelJob {
// Contribute on main thread.
main_task->Run();
delete main_task;
int aborted_tasks = 0;
// Wait for background tasks.
for (int i = 0; i < num_tasks_; i++) {
if (!cancelable_task_manager_->TryAbort(task_ids[i])) {
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) {
Item* item = items_;
while (item != nullptr) {
......@@ -112,6 +120,8 @@ class PageParallelJob {
}
}
void NotifyFinishedTask() { finished_tasks_->Increment(1); }
private:
static const int kMaxNumberOfTasks = 10;
......@@ -129,14 +139,16 @@ class PageParallelJob {
class Task : public CancelableTask {
public:
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()),
heap_(heap),
items_(items),
num_items_(num_items),
start_index_(start_index),
on_finish_(on_finish),
data_(data) {}
data_(data),
job_(job) {}
virtual ~Task() {}
......@@ -161,6 +173,7 @@ class PageParallelJob {
current = items_;
}
}
job_->NotifyFinishedTask();
on_finish_->Signal("PageParallelJob::Task::RunInternal");
}
......@@ -170,6 +183,7 @@ class PageParallelJob {
int start_index_;
base::Semaphore* on_finish_;
typename JobTraits::PerTaskData data_;
PageParallelJob<JobTraits>* job_;
DISALLOW_COPY_AND_ASSIGN(Task);
};
......@@ -179,6 +193,7 @@ class PageParallelJob {
int num_items_;
int num_tasks_;
base::Semaphore* pending_tasks_;
base::AtomicNumber<int>* finished_tasks_;
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