| 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 #ifndef V8_CANCELABLE_TASK_H_ | 5 #ifndef V8_CANCELABLE_TASK_H_ |
| 6 #define V8_CANCELABLE_TASK_H_ | 6 #define V8_CANCELABLE_TASK_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "include/v8-platform.h" | 10 #include "include/v8-platform.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // (3) The task is not yet running (or finished) so it is canceled and | 38 // (3) The task is not yet running (or finished) so it is canceled and |
| 39 // removed. | 39 // removed. |
| 40 // | 40 // |
| 41 enum TryAbortResult { kTaskRemoved, kTaskRunning, kTaskAborted }; | 41 enum TryAbortResult { kTaskRemoved, kTaskRunning, kTaskAborted }; |
| 42 TryAbortResult TryAbort(uint32_t id); | 42 TryAbortResult TryAbort(uint32_t id); |
| 43 | 43 |
| 44 // Cancels all remaining registered tasks and waits for tasks that are | 44 // Cancels all remaining registered tasks and waits for tasks that are |
| 45 // already running. This disallows subsequent Register calls. | 45 // already running. This disallows subsequent Register calls. |
| 46 void CancelAndWait(); | 46 void CancelAndWait(); |
| 47 | 47 |
| 48 // Tries to cancel all remaining registered tasks. The return value indicates |
| 49 // whether |
| 50 // |
| 51 // 1) No tasks were registered (kTaskRemoved), or |
| 52 // |
| 53 // 2) There is at least one remaining task that couldn't be cancelled |
| 54 // (kTaskRunning), or |
| 55 // |
| 56 // 3) All registered tasks were cancelled (kTaskAborted). |
| 57 TryAbortResult TryAbortAll(); |
| 58 |
| 48 private: | 59 private: |
| 49 // Only called by {Cancelable} destructor. The task is done with executing, | 60 // Only called by {Cancelable} destructor. The task is done with executing, |
| 50 // but needs to be removed. | 61 // but needs to be removed. |
| 51 void RemoveFinishedTask(uint32_t id); | 62 void RemoveFinishedTask(uint32_t id); |
| 52 | 63 |
| 53 // To mitigate the ABA problem, the api refers to tasks through an id. | 64 // To mitigate the ABA problem, the api refers to tasks through an id. |
| 54 uint32_t task_id_counter_; | 65 uint32_t task_id_counter_; |
| 55 | 66 |
| 56 // A set of cancelable tasks that are currently registered. | 67 // A set of cancelable tasks that are currently registered. |
| 57 std::map<uint32_t, Cancelable*> cancelable_tasks_; | 68 std::map<uint32_t, Cancelable*> cancelable_tasks_; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 private: | 176 private: |
| 166 Isolate* isolate_; | 177 Isolate* isolate_; |
| 167 DISALLOW_COPY_AND_ASSIGN(CancelableIdleTask); | 178 DISALLOW_COPY_AND_ASSIGN(CancelableIdleTask); |
| 168 }; | 179 }; |
| 169 | 180 |
| 170 | 181 |
| 171 } // namespace internal | 182 } // namespace internal |
| 172 } // namespace v8 | 183 } // namespace v8 |
| 173 | 184 |
| 174 #endif // V8_CANCELABLE_TASK_H_ | 185 #endif // V8_CANCELABLE_TASK_H_ |
| OLD | NEW |