| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 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_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ | 5 #ifndef V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ |
| 6 #define V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ | 6 #define V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ |
| 7 | 7 |
| 8 #include "include/v8-inspector.h" | 8 #include "include/v8-inspector.h" |
| 9 #include "include/v8-platform.h" | 9 #include "include/v8-platform.h" |
| 10 #include "include/v8.h" | 10 #include "include/v8.h" |
| 11 #include "src/base/atomic-utils.h" |
| 11 #include "src/base/macros.h" | 12 #include "src/base/macros.h" |
| 12 #include "src/base/platform/platform.h" | 13 #include "src/base/platform/platform.h" |
| 13 #include "src/locked-queue-inl.h" | 14 #include "src/locked-queue-inl.h" |
| 14 #include "src/vector.h" | 15 #include "src/vector.h" |
| 15 | 16 |
| 16 class TaskRunner : public v8::base::Thread { | 17 class TaskRunner : public v8::base::Thread { |
| 17 public: | 18 public: |
| 18 class Task { | 19 class Task { |
| 19 public: | 20 public: |
| 20 virtual ~Task() {} | 21 virtual ~Task() {} |
| (...skipping 11 matching lines...) Expand all Loading... |
| 32 | 33 |
| 33 // Should be called from the same thread and only from task. | 34 // Should be called from the same thread and only from task. |
| 34 void RunMessageLoop(bool only_protocol); | 35 void RunMessageLoop(bool only_protocol); |
| 35 void QuitMessageLoop(); | 36 void QuitMessageLoop(); |
| 36 | 37 |
| 37 // TaskRunner takes ownership. | 38 // TaskRunner takes ownership. |
| 38 void Append(Task* task); | 39 void Append(Task* task); |
| 39 | 40 |
| 40 static TaskRunner* FromContext(v8::Local<v8::Context>); | 41 static TaskRunner* FromContext(v8::Local<v8::Context>); |
| 41 | 42 |
| 43 void Terminate(); |
| 44 |
| 42 private: | 45 private: |
| 43 void InitializeContext(); | 46 void InitializeContext(); |
| 44 Task* GetNext(bool only_protocol); | 47 Task* GetNext(bool only_protocol); |
| 45 | 48 |
| 46 v8::ExtensionConfiguration* extensions_; | 49 v8::ExtensionConfiguration* extensions_; |
| 47 bool catch_exceptions_; | 50 bool catch_exceptions_; |
| 48 v8::base::Semaphore* ready_semaphore_; | 51 v8::base::Semaphore* ready_semaphore_; |
| 49 | 52 |
| 50 v8::Isolate* isolate_; | 53 v8::Isolate* isolate_; |
| 51 v8::Global<v8::Context> context_; | 54 v8::Global<v8::Context> context_; |
| 52 | 55 |
| 53 // deferred_queue_ combined with queue_ (in this order) have all tasks in the | 56 // deferred_queue_ combined with queue_ (in this order) have all tasks in the |
| 54 // correct order. | 57 // correct order. Sometimes we skip non-protocol tasks by moving them from |
| 55 // Sometimes we skip non-protocol tasks by moving them from queue_ to | 58 // queue_ to deferred_queue_. |
| 56 // deferred_queue_. | |
| 57 v8::internal::LockedQueue<Task*> queue_; | 59 v8::internal::LockedQueue<Task*> queue_; |
| 58 v8::internal::LockedQueue<Task*> deffered_queue_; | 60 v8::internal::LockedQueue<Task*> deffered_queue_; |
| 59 v8::base::Semaphore process_queue_semaphore_; | 61 v8::base::Semaphore process_queue_semaphore_; |
| 60 | 62 |
| 61 int nested_loop_count_; | 63 int nested_loop_count_; |
| 62 | 64 |
| 65 v8::base::AtomicNumber<int> is_terminated_; |
| 66 |
| 63 DISALLOW_COPY_AND_ASSIGN(TaskRunner); | 67 DISALLOW_COPY_AND_ASSIGN(TaskRunner); |
| 64 }; | 68 }; |
| 65 | 69 |
| 66 class ExecuteStringTask : public TaskRunner::Task { | 70 class ExecuteStringTask : public TaskRunner::Task { |
| 67 public: | 71 public: |
| 68 explicit ExecuteStringTask(const v8::internal::Vector<uint16_t>& expression); | 72 explicit ExecuteStringTask(const v8::internal::Vector<uint16_t>& expression); |
| 69 explicit ExecuteStringTask( | 73 explicit ExecuteStringTask( |
| 70 const v8::internal::Vector<const char>& expression); | 74 const v8::internal::Vector<const char>& expression); |
| 71 bool is_inspector_task() override { return false; } | 75 bool is_inspector_task() override { return false; } |
| 72 | 76 |
| 73 void Run(v8::Isolate* isolate, | 77 void Run(v8::Isolate* isolate, |
| 74 const v8::Global<v8::Context>& context) override; | 78 const v8::Global<v8::Context>& context) override; |
| 75 | 79 |
| 76 private: | 80 private: |
| 77 v8::internal::Vector<uint16_t> expression_; | 81 v8::internal::Vector<uint16_t> expression_; |
| 78 v8::internal::Vector<const char> expression_utf8_; | 82 v8::internal::Vector<const char> expression_utf8_; |
| 79 | 83 |
| 80 DISALLOW_COPY_AND_ASSIGN(ExecuteStringTask); | 84 DISALLOW_COPY_AND_ASSIGN(ExecuteStringTask); |
| 81 }; | 85 }; |
| 82 | 86 |
| 83 #endif // V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ | 87 #endif // V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ |
| OLD | NEW |