OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ | |
6 #define V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ | |
7 | |
8 #include "include/v8-inspector.h" | |
9 #include "include/v8-platform.h" | |
10 #include "include/v8.h" | |
11 #include "src/base/atomic-utils.h" | |
12 #include "src/base/macros.h" | |
13 #include "src/base/platform/platform.h" | |
14 #include "src/inspector/string-16.h" | |
15 #include "src/locked-queue-inl.h" | |
16 | |
17 class TaskScope { | |
dgozman
2016/09/23 03:09:56
STACK_ALLOCATED?
kozy
2016/09/23 17:05:20
I couldn't find any like this in macros.h.
Moved t
| |
18 public: | |
19 TaskScope(v8::Isolate* isolate, const v8::Global<v8::Context>& context); | |
20 ~TaskScope(); | |
21 | |
22 v8::Local<v8::Context> context() { return context_; } | |
23 | |
24 private: | |
25 v8::Isolate* isolate_; | |
26 v8::Isolate::Scope isolate_scope_; | |
27 v8::HandleScope handle_scope_; | |
28 v8::Local<v8::Context> context_; | |
29 v8::Context::Scope context_scope_; | |
30 v8::MicrotasksScope microtasks_scope_; | |
31 v8::TryCatch try_catch_; | |
32 | |
33 DISALLOW_COPY_AND_ASSIGN(TaskScope); | |
34 }; | |
35 | |
36 class Task : public v8::Task { | |
dgozman
2016/09/23 03:09:56
Let's make this inner class of TaskQueue to avoid
kozy
2016/09/23 17:05:20
Done.
| |
37 public: | |
38 virtual bool is_protocol_task() = 0; | |
39 virtual void Run(v8::Isolate* isolate, | |
40 const v8::Global<v8::Context>& context) { | |
41 DCHECK(false); | |
dgozman
2016/09/23 03:09:56
Just make it = 0
kozy
2016/09/23 17:05:20
Done.
| |
42 } | |
43 virtual void Run() { DCHECK(false); } | |
dgozman
2016/09/23 03:09:56
ditto
| |
44 }; | |
45 | |
46 class ExecuteStringTask : public Task { | |
47 public: | |
48 explicit ExecuteStringTask(const v8_inspector::StringView& expression); | |
49 bool is_protocol_task() { return false; } | |
dgozman
2016/09/23 03:09:56
override
kozy
2016/09/23 17:05:20
Done.
| |
50 | |
51 void Run(v8::Isolate* isolate, const v8::Global<v8::Context>& global_context); | |
52 | |
53 private: | |
54 v8_inspector::String16 expression_; | |
dgozman
2016/09/23 03:09:56
Let's avoid using String16.
kozy
2016/09/23 17:05:20
Done.
| |
55 | |
56 DISALLOW_COPY_AND_ASSIGN(ExecuteStringTask); | |
57 }; | |
58 | |
59 class TaskQueue { | |
60 public: | |
61 TaskQueue(); | |
62 ~TaskQueue(); | |
63 | |
64 void Append(Task* task); | |
65 Task* GetNext(bool only_protocol); | |
66 | |
67 void SetContext(v8::Local<v8::Context>); | |
68 static TaskQueue* FromContext(v8::Local<v8::Context>); | |
69 | |
70 private: | |
71 v8::internal::LockedQueue<Task*> queue_; | |
dgozman
2016/09/23 03:09:56
Can we use std::unique_ptr<Task>?
kozy
2016/09/23 17:05:20
LockedQueue doesn't ready for unique_ptr.
Added a
| |
72 v8::internal::LockedQueue<Task*> deffered_queue_; | |
73 v8::base::Semaphore process_queue_semaphore_; | |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(TaskQueue); | |
76 }; | |
77 | |
78 class TaskRunner : public v8::base::Thread { | |
79 public: | |
80 enum State { kRunning, kStopRequested }; | |
81 | |
82 explicit TaskRunner(TaskQueue* queue); | |
dgozman
2016/09/23 03:09:56
Shouldn't task runner create a queue itself?
kozy
2016/09/23 17:05:20
Done.
| |
83 virtual ~TaskRunner(); | |
84 | |
85 void SetContext(v8::Local<v8::Context>); | |
86 TaskQueue* Queue() const { return queue_; } | |
87 | |
88 // Thread implementation. | |
89 void Run() override; | |
90 void Stop(); | |
91 | |
92 private: | |
93 TaskQueue* queue_; | |
94 v8::base::AtomicValue<State> state_; | |
95 | |
96 v8::Isolate* isolate_; | |
97 v8::Global<v8::Context> context_; | |
98 | |
99 DISALLOW_COPY_AND_ASSIGN(TaskRunner); | |
100 }; | |
101 | |
102 #endif // V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ | |
OLD | NEW |