OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/cancelable-task.h" | 5 #include "src/cancelable-task.h" |
6 | 6 |
7 #include "src/base/platform/platform.h" | 7 #include "src/base/platform/platform.h" |
8 #include "src/isolate.h" | 8 #include "src/isolate.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 cancelable_tasks_.erase(current); | 86 cancelable_tasks_.erase(current); |
87 } | 87 } |
88 } | 88 } |
89 // Wait for already running background tasks. | 89 // Wait for already running background tasks. |
90 if (!cancelable_tasks_.empty()) { | 90 if (!cancelable_tasks_.empty()) { |
91 cancelable_tasks_barrier_.Wait(&mutex_); | 91 cancelable_tasks_barrier_.Wait(&mutex_); |
92 } | 92 } |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
| 96 CancelableTaskManager::TryAbortResult CancelableTaskManager::TryAbortAll() { |
| 97 // Clean up all cancelable fore- and background tasks. Tasks are canceled on |
| 98 // the way if possible, i.e., if they have not started yet. |
| 99 base::LockGuard<base::Mutex> guard(&mutex_); |
| 100 |
| 101 if (cancelable_tasks_.empty()) return kTaskRemoved; |
| 102 |
| 103 for (auto it = cancelable_tasks_.begin(); it != cancelable_tasks_.end();) { |
| 104 if (it->second->Cancel()) { |
| 105 it = cancelable_tasks_.erase(it); |
| 106 } else { |
| 107 ++it; |
| 108 } |
| 109 } |
| 110 |
| 111 return cancelable_tasks_.empty() ? kTaskAborted : kTaskRunning; |
| 112 } |
| 113 |
96 CancelableTask::CancelableTask(Isolate* isolate) | 114 CancelableTask::CancelableTask(Isolate* isolate) |
97 : CancelableTask(isolate, isolate->cancelable_task_manager()) {} | 115 : CancelableTask(isolate, isolate->cancelable_task_manager()) {} |
98 | 116 |
99 CancelableTask::CancelableTask(Isolate* isolate, CancelableTaskManager* manager) | 117 CancelableTask::CancelableTask(Isolate* isolate, CancelableTaskManager* manager) |
100 : Cancelable(manager), isolate_(isolate) {} | 118 : Cancelable(manager), isolate_(isolate) {} |
101 | 119 |
102 CancelableIdleTask::CancelableIdleTask(Isolate* isolate) | 120 CancelableIdleTask::CancelableIdleTask(Isolate* isolate) |
103 : CancelableIdleTask(isolate, isolate->cancelable_task_manager()) {} | 121 : CancelableIdleTask(isolate, isolate->cancelable_task_manager()) {} |
104 | 122 |
105 CancelableIdleTask::CancelableIdleTask(Isolate* isolate, | 123 CancelableIdleTask::CancelableIdleTask(Isolate* isolate, |
106 CancelableTaskManager* manager) | 124 CancelableTaskManager* manager) |
107 : Cancelable(manager), isolate_(isolate) {} | 125 : Cancelable(manager), isolate_(isolate) {} |
108 | 126 |
109 } // namespace internal | 127 } // namespace internal |
110 } // namespace v8 | 128 } // namespace v8 |
OLD | NEW |