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 #include "test/inspector-protocol/task-runner.h" |
| 6 |
| 7 #include "test/inspector-protocol/task-queue.h" |
| 8 #include "test/inspector-protocol/task.h" |
| 9 |
| 10 namespace v8_inspector { |
| 11 |
| 12 TaskRunner::TaskRunner(TaskQueue* queue) |
| 13 : Thread(Options("Task Runner")), |
| 14 queue_(queue), |
| 15 state_(TaskRunner::kRunning), |
| 16 isolate_(NULL) { |
| 17 Start(); |
| 18 } |
| 19 |
| 20 TaskRunner::~TaskRunner() { Join(); } |
| 21 |
| 22 void TaskRunner::SetContext(v8::Local<v8::Context> context) { |
| 23 isolate_ = context->GetIsolate(); |
| 24 context_.Reset(isolate_, context); |
| 25 } |
| 26 |
| 27 void TaskRunner::Run() { |
| 28 while (true) { |
| 29 Task* task = queue_->GetNext(false); |
| 30 if (!task) return; |
| 31 if (isolate_) |
| 32 task->Run(isolate_, context_); |
| 33 else |
| 34 task->Run(); |
| 35 delete task; |
| 36 if (state_.Value() == kStopRequested) return; |
| 37 } |
| 38 } |
| 39 |
| 40 void TaskRunner::Stop() { state_.SetValue(kStopRequested); } |
| 41 |
| 42 } // v8_inspector |
OLD | NEW |