Skip to content

Commit de7403f

Browse files
addaleaxtargos
authored andcommittedJun 13, 2018
src: cleanup per-isolate state on platform on isolate unregister
Clean up once all references to an `Isolate*` are gone from the `NodePlatform`, rather than waiting for the `PerIsolatePlatformData` struct to be deleted since there may be cyclic references between that struct and the individual tasks. PR-URL: #20876 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Shingo Inoue <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
1 parent 9047c81 commit de7403f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
 

‎src/node_platform.cc

+11
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
}

0 commit comments

Comments
 (0)
Please sign in to comment.