◐ Shell
clean mode source ↗

src: cleanup per-isolate state on platform on isolate unregister · nodejs/node@de7403f

Original file line numberDiff line numberDiff line change

@@ -82,12 +82,14 @@ void PerIsolatePlatformData::PostIdleTask(std::unique_ptr<v8::IdleTask> task) {

8282

}

8383
8484

void PerIsolatePlatformData::PostTask(std::unique_ptr<Task> task) {

85+

CHECK_NE(flush_tasks_, nullptr);

8586

foreground_tasks_.Push(std::move(task));

8687

uv_async_send(flush_tasks_);

8788

}

8889
8990

void PerIsolatePlatformData::PostDelayedTask(

9091

std::unique_ptr<Task> task, double delay_in_seconds) {

92+

CHECK_NE(flush_tasks_, nullptr);

9193

std::unique_ptr<DelayedTask> delayed(new DelayedTask());

9294

delayed->task = std::move(task);

9395

delayed->platform_data = shared_from_this();

@@ -97,13 +99,21 @@ void PerIsolatePlatformData::PostDelayedTask(

9799

}

98100
99101

PerIsolatePlatformData::~PerIsolatePlatformData() {

102+

Shutdown();

103+

}

104+
105+

void PerIsolatePlatformData::Shutdown() {

106+

if (flush_tasks_ == nullptr)

107+

return;

108+
100109

while (FlushForegroundTasksInternal()) {}

101110

CancelPendingDelayedTasks();

102111
103112

uv_close(reinterpret_cast<uv_handle_t*>(flush_tasks_),

104113

[](uv_handle_t* handle) {

105114

delete reinterpret_cast<uv_async_t*>(handle);

106115

});

116+

flush_tasks_ = nullptr;

107117

}

108118
109119

void PerIsolatePlatformData::ref() {

@@ -144,6 +154,7 @@ void NodePlatform::UnregisterIsolate(IsolateData* isolate_data) {

144154

std::shared_ptr<PerIsolatePlatformData> existing = per_isolate_[isolate];

145155

CHECK(existing);

146156

if (existing->unref() == 0) {

157+

existing->Shutdown();

147158

per_isolate_.erase(isolate);

148159

}

149160

}