Skip to content

Commit

Permalink
src: use env->RequestInterrupt() for inspector io thread start
Browse files Browse the repository at this point in the history
This cleans up `Agent::RequestIoThreadStart()` significantly.

Backport-PR-URL: #35241
PR-URL: #32523
Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax committed Sep 23, 2020
1 parent 4704e58 commit 2e4536e
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ using v8::Local;
using v8::Message;
using v8::Object;
using v8::Task;
using v8::TaskRunner;
using v8::Value;
using v8_inspector::StringBuffer;
using v8_inspector::StringView;
Expand All @@ -61,18 +60,6 @@ static std::atomic_bool start_io_thread_async_initialized { false };
// Protects the Agent* stored in start_io_thread_async.data.
static Mutex start_io_thread_async_mutex;

class StartIoTask : public Task {
public:
explicit StartIoTask(Agent* agent) : agent(agent) {}

void Run() override {
agent->StartIoThread();
}

private:
Agent* agent;
};

std::unique_ptr<StringBuffer> ToProtocolString(Isolate* isolate,
Local<Value> value) {
TwoByteValue buffer(isolate, value);
Expand All @@ -84,10 +71,6 @@ void StartIoThreadAsyncCallback(uv_async_t* handle) {
static_cast<Agent*>(handle->data)->StartIoThread();
}

void StartIoInterrupt(Isolate* isolate, void* agent) {
static_cast<Agent*>(agent)->StartIoThread();
}


#ifdef __POSIX__
static void StartIoThreadWakeup(int signo) {
Expand Down Expand Up @@ -981,12 +964,10 @@ void Agent::RequestIoThreadStart() {
// for IO events)
CHECK(start_io_thread_async_initialized);
uv_async_send(&start_io_thread_async);
Isolate* isolate = parent_env_->isolate();
v8::Platform* platform = parent_env_->isolate_data()->platform();
std::shared_ptr<TaskRunner> taskrunner =
platform->GetForegroundTaskRunner(isolate);
taskrunner->PostTask(std::make_unique<StartIoTask>(this));
isolate->RequestInterrupt(StartIoInterrupt, this);
parent_env_->RequestInterrupt([this](Environment*) {
StartIoThread();
});

CHECK(start_io_thread_async_initialized);
uv_async_send(&start_io_thread_async);
}
Expand Down

0 comments on commit 2e4536e

Please sign in to comment.