Commit ea511e76 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[inspector] finish test runner gracefully..

.. to make windows bot happy.

BUG=chromium:635948
R=dgozman@chromium.org

Review-Url: https://chromiumcodereview.appspot.com/2428213002
Cr-Commit-Position: refs/heads/master@{#40415}
parent 55091044
include_rules = [
"-src",
"+src/base/atomic-utils.h",
"+src/base/macros.h",
"+src/base/platform/platform.h",
"+src/flags.h",
......
......@@ -103,8 +103,10 @@ var actions = [ "stepOut", "print", "stepOut", "print", "stepOut", "print",
function runAction(response)
{
var action = actions.shift();
if (!action)
if (!action) {
InspectorTest.completeTest();
return;
}
if (action === "print") {
printCallFrames(response.params.callFrames);
......
......@@ -21,10 +21,21 @@
namespace {
std::vector<TaskRunner*> task_runners;
void Terminate() {
for (size_t i = 0; i < task_runners.size(); ++i) {
task_runners[i]->Terminate();
task_runners[i]->Join();
}
std::vector<TaskRunner*> empty;
task_runners.swap(empty);
}
void Exit() {
fflush(stdout);
fflush(stderr);
_exit(0);
Terminate();
}
class UtilsExtension : public v8::Extension {
......@@ -282,6 +293,9 @@ int main(int argc, char* argv[]) {
&ready_semaphore);
ready_semaphore.Wait();
task_runners.push_back(&frontend_runner);
task_runners.push_back(&backend_runner);
for (int i = 1; i < argc; ++i) {
if (argv[i][0] == '-') break;
......@@ -297,5 +311,6 @@ int main(int argc, char* argv[]) {
}
frontend_runner.Join();
backend_runner.Join();
return 0;
}
......@@ -63,8 +63,9 @@ void TaskRunner::Run() {
void TaskRunner::RunMessageLoop(bool only_protocol) {
int loop_number = ++nested_loop_count_;
while (nested_loop_count_ == loop_number) {
while (nested_loop_count_ == loop_number && !is_terminated_.Value()) {
TaskRunner::Task* task = GetNext(only_protocol);
if (!task) return;
v8::Isolate::Scope isolate_scope(isolate_);
if (catch_exceptions_) {
v8::TryCatch try_catch(isolate_);
......@@ -93,8 +94,14 @@ void TaskRunner::Append(Task* task) {
process_queue_semaphore_.Signal();
}
void TaskRunner::Terminate() {
is_terminated_.Increment(1);
process_queue_semaphore_.Signal();
}
TaskRunner::Task* TaskRunner::GetNext(bool only_protocol) {
for (;;) {
if (is_terminated_.Value()) return nullptr;
if (only_protocol) {
Task* task = nullptr;
if (queue_.Dequeue(&task)) {
......@@ -108,7 +115,6 @@ TaskRunner::Task* TaskRunner::GetNext(bool only_protocol) {
}
process_queue_semaphore_.Wait();
}
UNREACHABLE();
return nullptr;
}
......
......@@ -8,6 +8,7 @@
#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/locked-queue-inl.h"
......@@ -39,6 +40,8 @@ class TaskRunner : public v8::base::Thread {
static TaskRunner* FromContext(v8::Local<v8::Context>);
void Terminate();
private:
void InitializeContext();
Task* GetNext(bool only_protocol);
......@@ -51,15 +54,16 @@ class TaskRunner : public v8::base::Thread {
v8::Global<v8::Context> context_;
// deferred_queue_ combined with queue_ (in this order) have all tasks in the
// correct order.
// Sometimes we skip non-protocol tasks by moving them from queue_ to
// deferred_queue_.
// correct order. Sometimes we skip non-protocol tasks by moving them from
// queue_ to deferred_queue_.
v8::internal::LockedQueue<Task*> queue_;
v8::internal::LockedQueue<Task*> deffered_queue_;
v8::base::Semaphore process_queue_semaphore_;
int nested_loop_count_;
v8::base::AtomicNumber<int> is_terminated_;
DISALLOW_COPY_AND_ASSIGN(TaskRunner);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment