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>
|
2019-09-13 16:11:40 +00:00
|
|
|
#include <memory>
|
2017-01-31 00:19:41 +00:00
|
|
|
|
2016-09-30 15:52:31 +00:00
|
|
|
#include "include/v8-inspector.h"
|
|
|
|
#include "include/v8-platform.h"
|
|
|
|
#include "src/base/macros.h"
|
|
|
|
#include "src/base/platform/platform.h"
|
2021-06-17 15:43:55 +00:00
|
|
|
#include "src/base/vector.h"
|
2019-05-23 13:27:57 +00:00
|
|
|
#include "src/utils/locked-queue-inl.h"
|
2017-05-17 00:30:52 +00:00
|
|
|
#include "test/inspector/isolate-data.h"
|
2017-01-31 00:19:41 +00:00
|
|
|
|
2020-10-27 13:52:22 +00:00
|
|
|
namespace v8 {
|
2021-08-23 13:01:06 +00:00
|
|
|
|
|
|
|
class StartupData;
|
|
|
|
|
2020-10-27 13:52:22 +00:00
|
|
|
namespace internal {
|
|
|
|
|
2020-11-12 12:57:48 +00:00
|
|
|
enum CatchExceptions {
|
|
|
|
kFailOnUncaughtExceptions,
|
|
|
|
kStandardPropagateUncaughtExceptions,
|
|
|
|
kSuppressUncaughtExceptions
|
2020-11-09 13:52:29 +00:00
|
|
|
};
|
|
|
|
|
2016-09-30 15:52:31 +00:00
|
|
|
class TaskRunner : public v8::base::Thread {
|
|
|
|
public:
|
|
|
|
class Task {
|
|
|
|
public:
|
2018-09-18 08:26:42 +00:00
|
|
|
virtual ~Task() = default;
|
2017-05-22 20:46:42 +00:00
|
|
|
virtual bool is_priority_task() = 0;
|
2021-08-24 13:00:06 +00:00
|
|
|
virtual void Run(InspectorIsolateData* data) = 0;
|
2016-09-30 15:52:31 +00:00
|
|
|
};
|
|
|
|
|
2021-08-24 13:00:06 +00:00
|
|
|
TaskRunner(InspectorIsolateData::SetupGlobalTasks setup_global_tasks,
|
2020-11-09 13:52:29 +00:00
|
|
|
CatchExceptions catch_exceptions,
|
|
|
|
v8::base::Semaphore* ready_semaphore,
|
|
|
|
v8::StartupData* startup_data, WithInspector with_inspector);
|
2018-09-14 14:52:24 +00:00
|
|
|
~TaskRunner() override;
|
2020-11-06 02:39:19 +00:00
|
|
|
TaskRunner(const TaskRunner&) = delete;
|
|
|
|
TaskRunner& operator=(const TaskRunner&) = delete;
|
2021-08-24 13:00:06 +00:00
|
|
|
InspectorIsolateData* 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();
|
|
|
|
|
2020-11-05 16:15:32 +00:00
|
|
|
void Append(std::unique_ptr<Task>);
|
2020-12-24 10:08:09 +00:00
|
|
|
void InterruptForMessages();
|
2016-10-19 02:04:34 +00:00
|
|
|
void Terminate();
|
|
|
|
|
2016-09-30 15:52:31 +00:00
|
|
|
private:
|
2020-11-05 16:15:32 +00:00
|
|
|
std::unique_ptr<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
|
|
|
|
2021-08-24 13:00:06 +00:00
|
|
|
InspectorIsolateData::SetupGlobalTasks setup_global_tasks_;
|
2017-04-26 15:13:14 +00:00
|
|
|
v8::StartupData* startup_data_;
|
2020-11-09 13:52:29 +00:00
|
|
|
WithInspector with_inspector_;
|
|
|
|
CatchExceptions catch_exceptions_;
|
2016-09-30 15:52:31 +00:00
|
|
|
v8::base::Semaphore* ready_semaphore_;
|
2021-08-24 13:00:06 +00:00
|
|
|
std::unique_ptr<InspectorIsolateData> 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_.
|
2020-11-05 16:15:32 +00:00
|
|
|
v8::internal::LockedQueue<std::unique_ptr<Task>> queue_;
|
2020-11-05 16:16:29 +00:00
|
|
|
v8::internal::LockedQueue<std::unique_ptr<Task>> deferred_queue_;
|
2016-09-30 15:52:31 +00:00
|
|
|
v8::base::Semaphore process_queue_semaphore_;
|
|
|
|
|
|
|
|
int nested_loop_count_;
|
2018-07-11 16:37:32 +00:00
|
|
|
std::atomic<int> is_terminated_;
|
2016-09-30 15:52:31 +00:00
|
|
|
};
|
|
|
|
|
2020-10-27 13:52:22 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
2016-09-30 15:52:31 +00:00
|
|
|
#endif // V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_
|