Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Unified Diff: src/cancelable-task.cc

Issue 2413203004: [heap] Cancel tasks before tearing down the heap. (Closed)
Patch Set: cancel new tasks Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/cancelable-task.h ('k') | src/isolate.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/cancelable-task.cc
diff --git a/src/cancelable-task.cc b/src/cancelable-task.cc
index defbb44775a8c1f64b8eedac62ea21b8376eacd1..852f4ffda806bbc2266cd61ee64de2a5f421f419 100644
--- a/src/cancelable-task.cc
+++ b/src/cancelable-task.cc
@@ -26,14 +26,20 @@ Cancelable::~Cancelable() {
}
}
-CancelableTaskManager::CancelableTaskManager() : task_id_counter_(0) {}
+CancelableTaskManager::CancelableTaskManager()
+ : task_id_counter_(0), canceled_(false) {}
uint32_t CancelableTaskManager::Register(Cancelable* task) {
base::LockGuard<base::Mutex> guard(&mutex_);
uint32_t id = ++task_id_counter_;
// The loop below is just used when task_id_counter_ overflows.
while (cancelable_tasks_.count(id) > 0) ++id;
- cancelable_tasks_[id] = task;
+ if (canceled_) {
+ bool successfully_canceled_task = task->Cancel();
+ CHECK(successfully_canceled_task);
+ } else {
+ cancelable_tasks_[id] = task;
+ }
return id;
}
@@ -69,6 +75,7 @@ void CancelableTaskManager::CancelAndWait() {
// of canceling we wait for the background tasks that have already been
// started.
base::LockGuard<base::Mutex> guard(&mutex_);
+ canceled_ = true;
// Cancelable tasks could be running or could potentially register new
// tasks, requiring a loop here.
« no previous file with comments | « src/cancelable-task.h ('k') | src/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698