| 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 "include/v8-platform.h" | 8 #include "include/v8-platform.h" |
| 9 #include "src/atomic-utils.h" | 9 #include "src/atomic-utils.h" |
| 10 #include "src/base/macros.h" | 10 #include "src/base/macros.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // removed. | 36 // removed. |
| 37 // | 37 // |
| 38 // Returns {false} for (1) and (2), and {true} for (3). | 38 // Returns {false} for (1) and (2), and {true} for (3). |
| 39 bool TryAbort(uint32_t id); | 39 bool TryAbort(uint32_t id); |
| 40 | 40 |
| 41 // Cancels all remaining registered tasks and waits for tasks that are | 41 // Cancels all remaining registered tasks and waits for tasks that are |
| 42 // already running. | 42 // already running. |
| 43 void CancelAndWait(); | 43 void CancelAndWait(); |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 // Only called by {Cancelable} destructor. The task is done with executing, |
| 47 // but needs to be removed. |
| 48 void RemoveFinishedTask(uint32_t id); |
| 49 |
| 46 // To mitigate the ABA problem, the api refers to tasks through an id. | 50 // To mitigate the ABA problem, the api refers to tasks through an id. |
| 47 uint32_t task_id_counter_; | 51 uint32_t task_id_counter_; |
| 48 | 52 |
| 49 // A set of cancelable tasks that are currently registered. | 53 // A set of cancelable tasks that are currently registered. |
| 50 HashMap cancelable_tasks_; | 54 HashMap cancelable_tasks_; |
| 51 | 55 |
| 52 // Mutex and condition variable enabling concurrent register and removing, as | 56 // Mutex and condition variable enabling concurrent register and removing, as |
| 53 // well as waiting for background tasks on {CancelAndWait}. | 57 // well as waiting for background tasks on {CancelAndWait}. |
| 54 base::ConditionVariable cancelable_tasks_barrier_; | 58 base::ConditionVariable cancelable_tasks_barrier_; |
| 55 base::Mutex mutex_; | 59 base::Mutex mutex_; |
| 56 | 60 |
| 61 friend class Cancelable; |
| 62 |
| 57 DISALLOW_COPY_AND_ASSIGN(CancelableTaskManager); | 63 DISALLOW_COPY_AND_ASSIGN(CancelableTaskManager); |
| 58 }; | 64 }; |
| 59 | 65 |
| 60 | 66 |
| 61 class Cancelable { | 67 class Cancelable { |
| 62 public: | 68 public: |
| 63 explicit Cancelable(CancelableTaskManager* parent); | 69 explicit Cancelable(CancelableTaskManager* parent); |
| 64 virtual ~Cancelable(); | 70 virtual ~Cancelable(); |
| 65 | 71 |
| 66 // Never invoke after handing over the task to the platform! The reason is | 72 // Never invoke after handing over the task to the platform! The reason is |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 private: | 159 private: |
| 154 Isolate* isolate_; | 160 Isolate* isolate_; |
| 155 DISALLOW_COPY_AND_ASSIGN(CancelableIdleTask); | 161 DISALLOW_COPY_AND_ASSIGN(CancelableIdleTask); |
| 156 }; | 162 }; |
| 157 | 163 |
| 158 | 164 |
| 159 } // namespace internal | 165 } // namespace internal |
| 160 } // namespace v8 | 166 } // namespace v8 |
| 161 | 167 |
| 162 #endif // V8_CANCELABLE_TASK_H_ | 168 #endif // V8_CANCELABLE_TASK_H_ |
| OLD | NEW |