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/macros.h" |
| 12 #include "src/base/platform/platform.h" |
| 13 #include "src/inspector/string-16.h" |
| 14 #include "src/locked-queue-inl.h" |
| 15 |
| 16 class TaskRunner : public v8::base::Thread { |
| 17 public: |
| 18 class Task { |
| 19 public: |
| 20 virtual ~Task() {} |
| 21 virtual bool is_inspector_task() = 0; |
| 22 virtual void Run(v8::Isolate* isolate, |
| 23 const v8::Global<v8::Context>& context) = 0; |
| 24 }; |
| 25 |
| 26 explicit TaskRunner(v8::ExtensionConfiguration* extensions, |
| 27 v8::base::Semaphore* ready_semaphore); |
| 28 virtual ~TaskRunner(); |
| 29 |
| 30 // Thread implementation. |
| 31 void Run() override; |
| 32 |
| 33 // Should be called from the same thread and only from task. |
| 34 void RunMessageLoop(bool only_protocol); |
| 35 void QuitMessageLoop(); |
| 36 |
| 37 // TaskRunner takes ownership. |
| 38 void Append(Task* task); |
| 39 |
| 40 static TaskRunner* FromContext(v8::Local<v8::Context>); |
| 41 |
| 42 private: |
| 43 void InitializeContext(); |
| 44 Task* GetNext(bool only_protocol); |
| 45 |
| 46 v8::ExtensionConfiguration* extensions_; |
| 47 v8::base::Semaphore* ready_semaphore_; |
| 48 |
| 49 v8::Isolate* isolate_; |
| 50 v8::Global<v8::Context> context_; |
| 51 |
| 52 // deferred_queue_ combined with queue_ (in this order) have all tasks in the |
| 53 // correct order. |
| 54 // Sometimes we skip non-protocol tasks by moving them from queue_ to |
| 55 // deferred_queue_. |
| 56 v8::internal::LockedQueue<Task*> queue_; |
| 57 v8::internal::LockedQueue<Task*> deffered_queue_; |
| 58 v8::base::Semaphore process_queue_semaphore_; |
| 59 |
| 60 int nested_loop_count_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(TaskRunner); |
| 63 }; |
| 64 |
| 65 class ExecuteStringTask : public TaskRunner::Task { |
| 66 public: |
| 67 explicit ExecuteStringTask(const v8_inspector::StringView& expression); |
| 68 bool is_inspector_task() override { return false; } |
| 69 |
| 70 void Run(v8::Isolate* isolate, |
| 71 const v8::Global<v8::Context>& context) override; |
| 72 |
| 73 private: |
| 74 v8_inspector::String16 expression_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(ExecuteStringTask); |
| 77 }; |
| 78 |
| 79 #endif // V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ |
OLD | NEW |