Index: test/inspector-protocol/task-runner.h |
diff --git a/test/inspector-protocol/task-runner.h b/test/inspector-protocol/task-runner.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..517dc946e903255c530084f1306bdbd631e6858d |
--- /dev/null |
+++ b/test/inspector-protocol/task-runner.h |
@@ -0,0 +1,102 @@ |
+// Copyright 2016 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ |
+#define V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ |
+ |
+#include "include/v8-inspector.h" |
+#include "include/v8-platform.h" |
+#include "include/v8.h" |
+#include "src/base/atomic-utils.h" |
+#include "src/base/macros.h" |
+#include "src/base/platform/platform.h" |
+#include "src/inspector/string-16.h" |
+#include "src/locked-queue-inl.h" |
+ |
+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
|
+ public: |
+ TaskScope(v8::Isolate* isolate, const v8::Global<v8::Context>& context); |
+ ~TaskScope(); |
+ |
+ v8::Local<v8::Context> context() { return context_; } |
+ |
+ private: |
+ v8::Isolate* isolate_; |
+ v8::Isolate::Scope isolate_scope_; |
+ v8::HandleScope handle_scope_; |
+ v8::Local<v8::Context> context_; |
+ v8::Context::Scope context_scope_; |
+ v8::MicrotasksScope microtasks_scope_; |
+ v8::TryCatch try_catch_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TaskScope); |
+}; |
+ |
+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.
|
+ public: |
+ virtual bool is_protocol_task() = 0; |
+ virtual void Run(v8::Isolate* isolate, |
+ const v8::Global<v8::Context>& context) { |
+ DCHECK(false); |
dgozman
2016/09/23 03:09:56
Just make it = 0
kozy
2016/09/23 17:05:20
Done.
|
+ } |
+ virtual void Run() { DCHECK(false); } |
dgozman
2016/09/23 03:09:56
ditto
|
+}; |
+ |
+class ExecuteStringTask : public Task { |
+ public: |
+ explicit ExecuteStringTask(const v8_inspector::StringView& expression); |
+ bool is_protocol_task() { return false; } |
dgozman
2016/09/23 03:09:56
override
kozy
2016/09/23 17:05:20
Done.
|
+ |
+ void Run(v8::Isolate* isolate, const v8::Global<v8::Context>& global_context); |
+ |
+ private: |
+ v8_inspector::String16 expression_; |
dgozman
2016/09/23 03:09:56
Let's avoid using String16.
kozy
2016/09/23 17:05:20
Done.
|
+ |
+ DISALLOW_COPY_AND_ASSIGN(ExecuteStringTask); |
+}; |
+ |
+class TaskQueue { |
+ public: |
+ TaskQueue(); |
+ ~TaskQueue(); |
+ |
+ void Append(Task* task); |
+ Task* GetNext(bool only_protocol); |
+ |
+ void SetContext(v8::Local<v8::Context>); |
+ static TaskQueue* FromContext(v8::Local<v8::Context>); |
+ |
+ private: |
+ 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
|
+ v8::internal::LockedQueue<Task*> deffered_queue_; |
+ v8::base::Semaphore process_queue_semaphore_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TaskQueue); |
+}; |
+ |
+class TaskRunner : public v8::base::Thread { |
+ public: |
+ enum State { kRunning, kStopRequested }; |
+ |
+ 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.
|
+ virtual ~TaskRunner(); |
+ |
+ void SetContext(v8::Local<v8::Context>); |
+ TaskQueue* Queue() const { return queue_; } |
+ |
+ // Thread implementation. |
+ void Run() override; |
+ void Stop(); |
+ |
+ private: |
+ TaskQueue* queue_; |
+ v8::base::AtomicValue<State> state_; |
+ |
+ v8::Isolate* isolate_; |
+ v8::Global<v8::Context> context_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TaskRunner); |
+}; |
+ |
+#endif // V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ |