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" |
11 #include "src/base/atomic-utils.h" | 11 #include "src/base/atomic-utils.h" |
12 #include "src/base/macros.h" | 12 #include "src/base/macros.h" |
13 #include "src/base/platform/condition-variable.h" | 13 #include "src/base/platform/condition-variable.h" |
| 14 #include "src/globals.h" |
14 | 15 |
15 namespace v8 { | 16 namespace v8 { |
16 namespace internal { | 17 namespace internal { |
17 | 18 |
18 class Cancelable; | 19 class Cancelable; |
19 class Isolate; | 20 class Isolate; |
20 | 21 |
21 | 22 |
22 // Keeps track of cancelable tasks. It is possible to register and remove tasks | 23 // Keeps track of cancelable tasks. It is possible to register and remove tasks |
23 // from any fore- and background task/thread. | 24 // from any fore- and background task/thread. |
24 class CancelableTaskManager { | 25 class V8_EXPORT_PRIVATE CancelableTaskManager { |
25 public: | 26 public: |
26 CancelableTaskManager(); | 27 CancelableTaskManager(); |
27 | 28 |
28 // Registers a new cancelable {task}. Returns the unique {id} of the task that | 29 // Registers a new cancelable {task}. Returns the unique {id} of the task that |
29 // can be used to try to abort a task by calling {Abort}. | 30 // can be used to try to abort a task by calling {Abort}. |
30 // Must not be called after CancelAndWait. | 31 // Must not be called after CancelAndWait. |
31 uint32_t Register(Cancelable* task); | 32 uint32_t Register(Cancelable* task); |
32 | 33 |
33 // Try to abort running a task identified by {id}. The possible outcomes are: | 34 // Try to abort running a task identified by {id}. The possible outcomes are: |
34 // (1) The task is already finished running and thus has been removed from | 35 // (1) The task is already finished running and thus has been removed from |
(...skipping 25 matching lines...) Expand all Loading... |
60 base::ConditionVariable cancelable_tasks_barrier_; | 61 base::ConditionVariable cancelable_tasks_barrier_; |
61 base::Mutex mutex_; | 62 base::Mutex mutex_; |
62 | 63 |
63 bool canceled_; | 64 bool canceled_; |
64 | 65 |
65 friend class Cancelable; | 66 friend class Cancelable; |
66 | 67 |
67 DISALLOW_COPY_AND_ASSIGN(CancelableTaskManager); | 68 DISALLOW_COPY_AND_ASSIGN(CancelableTaskManager); |
68 }; | 69 }; |
69 | 70 |
70 | 71 class V8_EXPORT_PRIVATE Cancelable { |
71 class Cancelable { | |
72 public: | 72 public: |
73 explicit Cancelable(CancelableTaskManager* parent); | 73 explicit Cancelable(CancelableTaskManager* parent); |
74 virtual ~Cancelable(); | 74 virtual ~Cancelable(); |
75 | 75 |
76 // Never invoke after handing over the task to the platform! The reason is | 76 // Never invoke after handing over the task to the platform! The reason is |
77 // that {Cancelable} is used in combination with {v8::Task} and handed to | 77 // that {Cancelable} is used in combination with {v8::Task} and handed to |
78 // a platform. This step transfers ownership to the platform, which destroys | 78 // a platform. This step transfers ownership to the platform, which destroys |
79 // the task after running it. Since the exact time is not known, we cannot | 79 // the task after running it. Since the exact time is not known, we cannot |
80 // access the object after handing it to a platform. | 80 // access the object after handing it to a platform. |
81 uint32_t id() { return id_; } | 81 uint32_t id() { return id_; } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 private: | 163 private: |
164 Isolate* isolate_; | 164 Isolate* isolate_; |
165 DISALLOW_COPY_AND_ASSIGN(CancelableIdleTask); | 165 DISALLOW_COPY_AND_ASSIGN(CancelableIdleTask); |
166 }; | 166 }; |
167 | 167 |
168 | 168 |
169 } // namespace internal | 169 } // namespace internal |
170 } // namespace v8 | 170 } // namespace v8 |
171 | 171 |
172 #endif // V8_CANCELABLE_TASK_H_ | 172 #endif // V8_CANCELABLE_TASK_H_ |
OLD | NEW |