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 22 matching lines...) Expand all Loading... |
33 // (1) The task is already finished running and thus has been removed from | 33 // (1) The task is already finished running and thus has been removed from |
34 // the manager. | 34 // the manager. |
35 // (2) The task is currently running and cannot be canceled anymore. | 35 // (2) The task is currently running and cannot be canceled anymore. |
36 // (3) The task is not yet running (or finished) so it is canceled and | 36 // (3) The task is not yet running (or finished) so it is canceled and |
37 // removed. | 37 // removed. |
38 // | 38 // |
39 // Returns {false} for (1) and (2), and {true} for (3). | 39 // Returns {false} for (1) and (2), and {true} for (3). |
40 bool TryAbort(uint32_t id); | 40 bool TryAbort(uint32_t id); |
41 | 41 |
42 // Cancels all remaining registered tasks and waits for tasks that are | 42 // Cancels all remaining registered tasks and waits for tasks that are |
43 // already running. After this function is called all subsequent new tasks | 43 // already running. |
44 // will be cancelled on creation. | |
45 void CancelAndWait(); | 44 void CancelAndWait(); |
46 | 45 |
47 private: | 46 private: |
48 // Only called by {Cancelable} destructor. The task is done with executing, | 47 // Only called by {Cancelable} destructor. The task is done with executing, |
49 // but needs to be removed. | 48 // but needs to be removed. |
50 void RemoveFinishedTask(uint32_t id); | 49 void RemoveFinishedTask(uint32_t id); |
51 | 50 |
52 // To mitigate the ABA problem, the api refers to tasks through an id. | 51 // To mitigate the ABA problem, the api refers to tasks through an id. |
53 uint32_t task_id_counter_; | 52 uint32_t task_id_counter_; |
54 | 53 |
55 // A set of cancelable tasks that are currently registered. | 54 // A set of cancelable tasks that are currently registered. |
56 std::map<uint32_t, Cancelable*> cancelable_tasks_; | 55 std::map<uint32_t, Cancelable*> cancelable_tasks_; |
57 | 56 |
58 // Mutex and condition variable enabling concurrent register and removing, as | 57 // Mutex and condition variable enabling concurrent register and removing, as |
59 // well as waiting for background tasks on {CancelAndWait}. | 58 // well as waiting for background tasks on {CancelAndWait}. |
60 base::ConditionVariable cancelable_tasks_barrier_; | 59 base::ConditionVariable cancelable_tasks_barrier_; |
61 base::Mutex mutex_; | 60 base::Mutex mutex_; |
62 | 61 |
63 bool canceled_; | |
64 | |
65 friend class Cancelable; | 62 friend class Cancelable; |
66 | 63 |
67 DISALLOW_COPY_AND_ASSIGN(CancelableTaskManager); | 64 DISALLOW_COPY_AND_ASSIGN(CancelableTaskManager); |
68 }; | 65 }; |
69 | 66 |
70 | 67 |
71 class Cancelable { | 68 class Cancelable { |
72 public: | 69 public: |
73 explicit Cancelable(CancelableTaskManager* parent); | 70 explicit Cancelable(CancelableTaskManager* parent); |
74 virtual ~Cancelable(); | 71 virtual ~Cancelable(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 private: | 160 private: |
164 Isolate* isolate_; | 161 Isolate* isolate_; |
165 DISALLOW_COPY_AND_ASSIGN(CancelableIdleTask); | 162 DISALLOW_COPY_AND_ASSIGN(CancelableIdleTask); |
166 }; | 163 }; |
167 | 164 |
168 | 165 |
169 } // namespace internal | 166 } // namespace internal |
170 } // namespace v8 | 167 } // namespace v8 |
171 | 168 |
172 #endif // V8_CANCELABLE_TASK_H_ | 169 #endif // V8_CANCELABLE_TASK_H_ |
OLD | NEW |