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 #include "test/inspector/task-runner.h" | 5 #include "test/inspector/task-runner.h" |
6 | 6 |
7 #if !defined(_WIN32) && !defined(_WIN64) | 7 #if !defined(_WIN32) && !defined(_WIN64) |
8 #include <unistd.h> // NOLINT | 8 #include <unistd.h> // NOLINT |
9 #endif // !defined(_WIN32) && !defined(_WIN64) | 9 #endif // !defined(_WIN32) && !defined(_WIN64) |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 if (ready_semaphore_) ready_semaphore_->Signal(); | 56 if (ready_semaphore_) ready_semaphore_->Signal(); |
57 } | 57 } |
58 | 58 |
59 void TaskRunner::Run() { | 59 void TaskRunner::Run() { |
60 InitializeContext(); | 60 InitializeContext(); |
61 RunMessageLoop(false); | 61 RunMessageLoop(false); |
62 } | 62 } |
63 | 63 |
64 void TaskRunner::RunMessageLoop(bool only_protocol) { | 64 void TaskRunner::RunMessageLoop(bool only_protocol) { |
65 int loop_number = ++nested_loop_count_; | 65 int loop_number = ++nested_loop_count_; |
66 while (nested_loop_count_ == loop_number) { | 66 while (nested_loop_count_ == loop_number && !is_terminated_.Value()) { |
67 TaskRunner::Task* task = GetNext(only_protocol); | 67 TaskRunner::Task* task = GetNext(only_protocol); |
| 68 if (!task) return; |
68 v8::Isolate::Scope isolate_scope(isolate_); | 69 v8::Isolate::Scope isolate_scope(isolate_); |
69 if (catch_exceptions_) { | 70 if (catch_exceptions_) { |
70 v8::TryCatch try_catch(isolate_); | 71 v8::TryCatch try_catch(isolate_); |
71 task->Run(isolate_, context_); | 72 task->Run(isolate_, context_); |
72 delete task; | 73 delete task; |
73 if (try_catch.HasCaught()) { | 74 if (try_catch.HasCaught()) { |
74 ReportUncaughtException(isolate_, try_catch); | 75 ReportUncaughtException(isolate_, try_catch); |
75 fflush(stdout); | 76 fflush(stdout); |
76 fflush(stderr); | 77 fflush(stderr); |
77 _exit(0); | 78 _exit(0); |
78 } | 79 } |
79 } else { | 80 } else { |
80 task->Run(isolate_, context_); | 81 task->Run(isolate_, context_); |
81 delete task; | 82 delete task; |
82 } | 83 } |
83 } | 84 } |
84 } | 85 } |
85 | 86 |
86 void TaskRunner::QuitMessageLoop() { | 87 void TaskRunner::QuitMessageLoop() { |
87 DCHECK(nested_loop_count_ > 0); | 88 DCHECK(nested_loop_count_ > 0); |
88 --nested_loop_count_; | 89 --nested_loop_count_; |
89 } | 90 } |
90 | 91 |
91 void TaskRunner::Append(Task* task) { | 92 void TaskRunner::Append(Task* task) { |
92 queue_.Enqueue(task); | 93 queue_.Enqueue(task); |
93 process_queue_semaphore_.Signal(); | 94 process_queue_semaphore_.Signal(); |
94 } | 95 } |
95 | 96 |
| 97 void TaskRunner::Terminate() { |
| 98 is_terminated_.Increment(1); |
| 99 process_queue_semaphore_.Signal(); |
| 100 } |
| 101 |
96 TaskRunner::Task* TaskRunner::GetNext(bool only_protocol) { | 102 TaskRunner::Task* TaskRunner::GetNext(bool only_protocol) { |
97 for (;;) { | 103 for (;;) { |
| 104 if (is_terminated_.Value()) return nullptr; |
98 if (only_protocol) { | 105 if (only_protocol) { |
99 Task* task = nullptr; | 106 Task* task = nullptr; |
100 if (queue_.Dequeue(&task)) { | 107 if (queue_.Dequeue(&task)) { |
101 if (task->is_inspector_task()) return task; | 108 if (task->is_inspector_task()) return task; |
102 deffered_queue_.Enqueue(task); | 109 deffered_queue_.Enqueue(task); |
103 } | 110 } |
104 } else { | 111 } else { |
105 Task* task = nullptr; | 112 Task* task = nullptr; |
106 if (deffered_queue_.Dequeue(&task)) return task; | 113 if (deffered_queue_.Dequeue(&task)) return task; |
107 if (queue_.Dequeue(&task)) return task; | 114 if (queue_.Dequeue(&task)) return task; |
108 } | 115 } |
109 process_queue_semaphore_.Wait(); | 116 process_queue_semaphore_.Wait(); |
110 } | 117 } |
111 UNREACHABLE(); | |
112 return nullptr; | 118 return nullptr; |
113 } | 119 } |
114 | 120 |
115 TaskRunner* TaskRunner::FromContext(v8::Local<v8::Context> context) { | 121 TaskRunner* TaskRunner::FromContext(v8::Local<v8::Context> context) { |
116 return static_cast<TaskRunner*>( | 122 return static_cast<TaskRunner*>( |
117 context->GetAlignedPointerFromEmbedderData(kTaskRunnerIndex)); | 123 context->GetAlignedPointerFromEmbedderData(kTaskRunnerIndex)); |
118 } | 124 } |
119 | 125 |
120 ExecuteStringTask::ExecuteStringTask( | 126 ExecuteStringTask::ExecuteStringTask( |
121 const v8::internal::Vector<uint16_t>& expression) | 127 const v8::internal::Vector<uint16_t>& expression) |
(...skipping 26 matching lines...) Expand all Loading... |
148 } | 154 } |
149 | 155 |
150 v8::ScriptCompiler::Source scriptSource(source, origin); | 156 v8::ScriptCompiler::Source scriptSource(source, origin); |
151 v8::Local<v8::Script> script; | 157 v8::Local<v8::Script> script; |
152 if (!v8::ScriptCompiler::Compile(local_context, &scriptSource) | 158 if (!v8::ScriptCompiler::Compile(local_context, &scriptSource) |
153 .ToLocal(&script)) | 159 .ToLocal(&script)) |
154 return; | 160 return; |
155 v8::MaybeLocal<v8::Value> result; | 161 v8::MaybeLocal<v8::Value> result; |
156 result = script->Run(local_context); | 162 result = script->Run(local_context); |
157 } | 163 } |
OLD | NEW |