Index: test/inspector-protocol/task-runner.cc |
diff --git a/test/inspector-protocol/task-runner.cc b/test/inspector-protocol/task-runner.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..040694036f716121ba5843a32bc44ba603f9ac2a |
--- /dev/null |
+++ b/test/inspector-protocol/task-runner.cc |
@@ -0,0 +1,42 @@ |
+// 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. |
+ |
+#include "test/inspector-protocol/task-runner.h" |
+ |
+#include "test/inspector-protocol/task-queue.h" |
+#include "test/inspector-protocol/task.h" |
+ |
+namespace v8_inspector { |
+ |
+TaskRunner::TaskRunner(TaskQueue* queue) |
+ : Thread(Options("Task Runner")), |
+ queue_(queue), |
+ state_(TaskRunner::kRunning), |
+ isolate_(NULL) { |
+ Start(); |
+} |
+ |
+TaskRunner::~TaskRunner() { Join(); } |
+ |
+void TaskRunner::SetContext(v8::Local<v8::Context> context) { |
+ isolate_ = context->GetIsolate(); |
+ context_.Reset(isolate_, context); |
+} |
+ |
+void TaskRunner::Run() { |
+ while (true) { |
+ Task* task = queue_->GetNext(false); |
+ if (!task) return; |
+ if (isolate_) |
+ task->Run(isolate_, context_); |
+ else |
+ task->Run(); |
+ delete task; |
+ if (state_.Value() == kStopRequested) return; |
+ } |
+} |
+ |
+void TaskRunner::Stop() { state_.SetValue(kStopRequested); } |
+ |
+} // v8_inspector |