Commit ddf83fb8 authored by ulan's avatar ulan Committed by Commit bot

[heap] Reland "Cancel tasks before tearing down the heap."

BUG=chromium:654343

Review-Url: https://codereview.chromium.org/2419783004
Cr-Commit-Position: refs/heads/master@{#40305}
parent 7d2c514d
...@@ -26,13 +26,15 @@ Cancelable::~Cancelable() { ...@@ -26,13 +26,15 @@ Cancelable::~Cancelable() {
} }
} }
CancelableTaskManager::CancelableTaskManager() : task_id_counter_(0) {} CancelableTaskManager::CancelableTaskManager()
: task_id_counter_(0), canceled_(false) {}
uint32_t CancelableTaskManager::Register(Cancelable* task) { uint32_t CancelableTaskManager::Register(Cancelable* task) {
base::LockGuard<base::Mutex> guard(&mutex_); base::LockGuard<base::Mutex> guard(&mutex_);
uint32_t id = ++task_id_counter_; uint32_t id = ++task_id_counter_;
// The loop below is just used when task_id_counter_ overflows. // The loop below is just used when task_id_counter_ overflows.
while (cancelable_tasks_.count(id) > 0) ++id; while (cancelable_tasks_.count(id) > 0) ++id;
CHECK(!canceled_);
cancelable_tasks_[id] = task; cancelable_tasks_[id] = task;
return id; return id;
} }
...@@ -69,6 +71,7 @@ void CancelableTaskManager::CancelAndWait() { ...@@ -69,6 +71,7 @@ void CancelableTaskManager::CancelAndWait() {
// of canceling we wait for the background tasks that have already been // of canceling we wait for the background tasks that have already been
// started. // started.
base::LockGuard<base::Mutex> guard(&mutex_); base::LockGuard<base::Mutex> guard(&mutex_);
canceled_ = true;
// Cancelable tasks could be running or could potentially register new // Cancelable tasks could be running or could potentially register new
// tasks, requiring a loop here. // tasks, requiring a loop here.
......
...@@ -27,6 +27,7 @@ class CancelableTaskManager { ...@@ -27,6 +27,7 @@ class CancelableTaskManager {
// Registers a new cancelable {task}. Returns the unique {id} of the task that // Registers a new cancelable {task}. Returns the unique {id} of the task that
// can be used to try to abort a task by calling {Abort}. // can be used to try to abort a task by calling {Abort}.
// Must not be called after CancelAndWait.
uint32_t Register(Cancelable* task); uint32_t Register(Cancelable* task);
// Try to abort running a task identified by {id}. The possible outcomes are: // Try to abort running a task identified by {id}. The possible outcomes are:
...@@ -40,7 +41,7 @@ class CancelableTaskManager { ...@@ -40,7 +41,7 @@ class CancelableTaskManager {
bool TryAbort(uint32_t id); bool TryAbort(uint32_t id);
// Cancels all remaining registered tasks and waits for tasks that are // Cancels all remaining registered tasks and waits for tasks that are
// already running. // already running. This disallows subsequent Register calls.
void CancelAndWait(); void CancelAndWait();
private: private:
...@@ -59,6 +60,8 @@ class CancelableTaskManager { ...@@ -59,6 +60,8 @@ class CancelableTaskManager {
base::ConditionVariable cancelable_tasks_barrier_; base::ConditionVariable cancelable_tasks_barrier_;
base::Mutex mutex_; base::Mutex mutex_;
bool canceled_;
friend class Cancelable; friend class Cancelable;
DISALLOW_COPY_AND_ASSIGN(CancelableTaskManager); DISALLOW_COPY_AND_ASSIGN(CancelableTaskManager);
......
...@@ -2227,13 +2227,14 @@ void Isolate::Deinit() { ...@@ -2227,13 +2227,14 @@ void Isolate::Deinit() {
delete heap_profiler_; delete heap_profiler_;
heap_profiler_ = NULL; heap_profiler_ = NULL;
cancelable_task_manager()->CancelAndWait();
heap_.TearDown(); heap_.TearDown();
logger_->TearDown(); logger_->TearDown();
delete interpreter_; delete interpreter_;
interpreter_ = NULL; interpreter_ = NULL;
cancelable_task_manager()->CancelAndWait();
delete compiler_dispatcher_tracer_; delete compiler_dispatcher_tracer_;
compiler_dispatcher_tracer_ = nullptr; compiler_dispatcher_tracer_ = nullptr;
......
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