| 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 | |
| 59 private: | 48 private: |
| 60 // Only called by {Cancelable} destructor. The task is done with executing, | 49 // Only called by {Cancelable} destructor. The task is done with executing, |
| 61 // but needs to be removed. | 50 // but needs to be removed. |
| 62 void RemoveFinishedTask(uint32_t id); | 51 void RemoveFinishedTask(uint32_t id); |
| 63 | 52 |
| 64 // To mitigate the ABA problem, the api refers to tasks through an id. | 53 // To mitigate the ABA problem, the api refers to tasks through an id. |
| 65 uint32_t task_id_counter_; | 54 uint32_t task_id_counter_; |
| 66 | 55 |
| 67 // A set of cancelable tasks that are currently registered. | 56 // A set of cancelable tasks that are currently registered. |
| 68 std::map<uint32_t, Cancelable*> cancelable_tasks_; | 57 std::map<uint32_t, Cancelable*> cancelable_tasks_; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 private: | 165 private: |
| 177 Isolate* isolate_; | 166 Isolate* isolate_; |
| 178 DISALLOW_COPY_AND_ASSIGN(CancelableIdleTask); | 167 DISALLOW_COPY_AND_ASSIGN(CancelableIdleTask); |
| 179 }; | 168 }; |
| 180 | 169 |
| 181 | 170 |
| 182 } // namespace internal | 171 } // namespace internal |
| 183 } // namespace v8 | 172 } // namespace v8 |
| 184 | 173 |
| 185 #endif // V8_CANCELABLE_TASK_H_ | 174 #endif // V8_CANCELABLE_TASK_H_ |
| OLD | NEW |