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> | |
9 | |
8 #include "include/v8-platform.h" | 10 #include "include/v8-platform.h" |
9 #include "src/atomic-utils.h" | 11 #include "src/atomic-utils.h" |
10 #include "src/base/macros.h" | 12 #include "src/base/macros.h" |
11 #include "src/base/platform/condition-variable.h" | 13 #include "src/base/platform/condition-variable.h" |
12 #include "src/hashmap.h" | |
13 | 14 |
14 namespace v8 { | 15 namespace v8 { |
15 namespace internal { | 16 namespace internal { |
16 | 17 |
17 class Cancelable; | 18 class Cancelable; |
18 class Isolate; | 19 class Isolate; |
19 | 20 |
20 | 21 |
21 // Keeps track of cancelable tasks. It is possible to register and remove tasks | 22 // Keeps track of cancelable tasks. It is possible to register and remove tasks |
22 // from any fore- and background task/thread. | 23 // from any fore- and background task/thread. |
(...skipping 21 matching lines...) Expand all Loading... | |
44 | 45 |
45 private: | 46 private: |
46 // Only called by {Cancelable} destructor. The task is done with executing, | 47 // Only called by {Cancelable} destructor. The task is done with executing, |
47 // but needs to be removed. | 48 // but needs to be removed. |
48 void RemoveFinishedTask(uint32_t id); | 49 void RemoveFinishedTask(uint32_t id); |
49 | 50 |
50 // 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. |
51 uint32_t task_id_counter_; | 52 uint32_t task_id_counter_; |
52 | 53 |
53 // A set of cancelable tasks that are currently registered. | 54 // A set of cancelable tasks that are currently registered. |
54 HashMap cancelable_tasks_; | 55 std::map<uint32_t, Cancelable*> cancelable_tasks_; |
Nico
2016/05/11 13:04:24
(if you don't need to ordering -- and given this w
| |
55 | 56 |
56 // Mutex and condition variable enabling concurrent register and removing, as | 57 // Mutex and condition variable enabling concurrent register and removing, as |
57 // well as waiting for background tasks on {CancelAndWait}. | 58 // well as waiting for background tasks on {CancelAndWait}. |
58 base::ConditionVariable cancelable_tasks_barrier_; | 59 base::ConditionVariable cancelable_tasks_barrier_; |
59 base::Mutex mutex_; | 60 base::Mutex mutex_; |
60 | 61 |
61 friend class Cancelable; | 62 friend class Cancelable; |
62 | 63 |
63 DISALLOW_COPY_AND_ASSIGN(CancelableTaskManager); | 64 DISALLOW_COPY_AND_ASSIGN(CancelableTaskManager); |
64 }; | 65 }; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 private: | 160 private: |
160 Isolate* isolate_; | 161 Isolate* isolate_; |
161 DISALLOW_COPY_AND_ASSIGN(CancelableIdleTask); | 162 DISALLOW_COPY_AND_ASSIGN(CancelableIdleTask); |
162 }; | 163 }; |
163 | 164 |
164 | 165 |
165 } // namespace internal | 166 } // namespace internal |
166 } // namespace v8 | 167 } // namespace v8 |
167 | 168 |
168 #endif // V8_CANCELABLE_TASK_H_ | 169 #endif // V8_CANCELABLE_TASK_H_ |
OLD | NEW |