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 | |
114 CancelableTask::CancelableTask(Isolate* isolate) | 96 CancelableTask::CancelableTask(Isolate* isolate) |
115 : CancelableTask(isolate, isolate->cancelable_task_manager()) {} | 97 : CancelableTask(isolate, isolate->cancelable_task_manager()) {} |
116 | 98 |
117 CancelableTask::CancelableTask(Isolate* isolate, CancelableTaskManager* manager) | 99 CancelableTask::CancelableTask(Isolate* isolate, CancelableTaskManager* manager) |
118 : Cancelable(manager), isolate_(isolate) {} | 100 : Cancelable(manager), isolate_(isolate) {} |
119 | 101 |
120 CancelableIdleTask::CancelableIdleTask(Isolate* isolate) | 102 CancelableIdleTask::CancelableIdleTask(Isolate* isolate) |
121 : CancelableIdleTask(isolate, isolate->cancelable_task_manager()) {} | 103 : CancelableIdleTask(isolate, isolate->cancelable_task_manager()) {} |
122 | 104 |
123 CancelableIdleTask::CancelableIdleTask(Isolate* isolate, | 105 CancelableIdleTask::CancelableIdleTask(Isolate* isolate, |
124 CancelableTaskManager* manager) | 106 CancelableTaskManager* manager) |
125 : Cancelable(manager), isolate_(isolate) {} | 107 : Cancelable(manager), isolate_(isolate) {} |
126 | 108 |
127 } // namespace internal | 109 } // namespace internal |
128 } // namespace v8 | 110 } // namespace v8 |
OLD | NEW |