2016-09-30 15:52:31 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
#ifndef V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_
|
|
|
|
#define V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_
|
|
|
|
|
2017-01-31 00:19:41 +00:00
|
|
|
#include <map>
|
|
|
|
|
2016-09-30 15:52:31 +00:00
|
|
|
#include "include/v8-inspector.h"
|
|
|
|
#include "include/v8-platform.h"
|
|
|
|
#include "include/v8.h"
|
|
|
|
#include "src/base/macros.h"
|
|
|
|
#include "src/base/platform/platform.h"
|
|
|
|
#include "src/locked-queue-inl.h"
|
2016-10-07 21:16:41 +00:00
|
|
|
#include "src/vector.h"
|
2017-05-17 00:30:52 +00:00
|
|
|
#include "test/inspector/isolate-data.h"
|
2017-01-31 00:19:41 +00:00
|
|
|
|
2016-09-30 15:52:31 +00:00
|
|
|
class TaskRunner : public v8::base::Thread {
|
|
|
|
public:
|
|
|
|
class Task {
|
|
|
|
public:
|
|
|
|
virtual ~Task() {}
|
2017-05-22 20:46:42 +00:00
|
|
|
virtual bool is_priority_task() = 0;
|
|
|
|
virtual void Run(IsolateData* data) = 0;
|
2016-09-30 15:52:31 +00:00
|
|
|
};
|
|
|
|
|
2017-05-16 23:14:46 +00:00
|
|
|
TaskRunner(IsolateData::SetupGlobalTasks setup_global_tasks,
|
|
|
|
bool catch_exceptions, v8::base::Semaphore* ready_semaphore,
|
2017-05-22 20:46:42 +00:00
|
|
|
v8::StartupData* startup_data, bool with_inspector);
|
2016-09-30 15:52:31 +00:00
|
|
|
virtual ~TaskRunner();
|
2017-05-16 23:14:46 +00:00
|
|
|
IsolateData* data() const { return data_.get(); }
|
2016-09-30 15:52:31 +00:00
|
|
|
|
|
|
|
// Thread implementation.
|
|
|
|
void Run() override;
|
|
|
|
|
|
|
|
// Should be called from the same thread and only from task.
|
|
|
|
void RunMessageLoop(bool only_protocol);
|
|
|
|
void QuitMessageLoop();
|
|
|
|
|
|
|
|
// TaskRunner takes ownership.
|
|
|
|
void Append(Task* task);
|
|
|
|
|
2016-10-19 02:04:34 +00:00
|
|
|
void Terminate();
|
|
|
|
|
2016-09-30 15:52:31 +00:00
|
|
|
private:
|
|
|
|
Task* GetNext(bool only_protocol);
|
2017-05-16 23:14:46 +00:00
|
|
|
v8::Isolate* isolate() const { return data_->isolate(); }
|
2016-09-30 15:52:31 +00:00
|
|
|
|
2017-05-16 23:14:46 +00:00
|
|
|
IsolateData::SetupGlobalTasks setup_global_tasks_;
|
2017-04-26 15:13:14 +00:00
|
|
|
v8::StartupData* startup_data_;
|
2017-05-22 20:46:42 +00:00
|
|
|
bool with_inspector_;
|
2016-10-05 15:07:57 +00:00
|
|
|
bool catch_exceptions_;
|
2016-09-30 15:52:31 +00:00
|
|
|
v8::base::Semaphore* ready_semaphore_;
|
2017-05-16 23:14:46 +00:00
|
|
|
std::unique_ptr<IsolateData> data_;
|
2016-09-30 15:52:31 +00:00
|
|
|
|
|
|
|
// deferred_queue_ combined with queue_ (in this order) have all tasks in the
|
2016-10-19 02:04:34 +00:00
|
|
|
// correct order. Sometimes we skip non-protocol tasks by moving them from
|
|
|
|
// queue_ to deferred_queue_.
|
2016-09-30 15:52:31 +00:00
|
|
|
v8::internal::LockedQueue<Task*> queue_;
|
|
|
|
v8::internal::LockedQueue<Task*> deffered_queue_;
|
|
|
|
v8::base::Semaphore process_queue_semaphore_;
|
|
|
|
|
|
|
|
int nested_loop_count_;
|
|
|
|
|
2018-07-11 16:37:32 +00:00
|
|
|
std::atomic<int> is_terminated_;
|
2016-10-19 02:04:34 +00:00
|
|
|
|
2016-09-30 15:52:31 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(TaskRunner);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_
|