diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-05-18 00:46:19 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-06-06 20:43:39 +0300 |
commit | 3bcad3c8f1991914c3ccb3335b7685859366b69a (patch) | |
tree | 6f486f349a1a5176c4febc55aea8b72456dac3da /src/node_platform.cc | |
parent | 99c51f196e62f1bb44019fe2e984af7415777f86 (diff) |
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: https://github.com/nodejs/node/pull/20876
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Diffstat (limited to 'src/node_platform.cc')
-rw-r--r-- | src/node_platform.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/node_platform.cc b/src/node_platform.cc index 2885c72ed71..6fc83950d30 100644 --- a/src/node_platform.cc +++ b/src/node_platform.cc @@ -82,12 +82,14 @@ void PerIsolatePlatformData::PostIdleTask(std::unique_ptr<v8::IdleTask> task) { } void PerIsolatePlatformData::PostTask(std::unique_ptr<Task> task) { + CHECK_NE(flush_tasks_, nullptr); foreground_tasks_.Push(std::move(task)); uv_async_send(flush_tasks_); } void PerIsolatePlatformData::PostDelayedTask( std::unique_ptr<Task> task, double delay_in_seconds) { + CHECK_NE(flush_tasks_, nullptr); std::unique_ptr<DelayedTask> delayed(new DelayedTask()); delayed->task = std::move(task); delayed->platform_data = shared_from_this(); @@ -97,6 +99,13 @@ void PerIsolatePlatformData::PostDelayedTask( } PerIsolatePlatformData::~PerIsolatePlatformData() { + Shutdown(); +} + +void PerIsolatePlatformData::Shutdown() { + if (flush_tasks_ == nullptr) + return; + while (FlushForegroundTasksInternal()) {} CancelPendingDelayedTasks(); @@ -104,6 +113,7 @@ PerIsolatePlatformData::~PerIsolatePlatformData() { [](uv_handle_t* handle) { delete reinterpret_cast<uv_async_t*>(handle); }); + flush_tasks_ = nullptr; } void PerIsolatePlatformData::ref() { @@ -144,6 +154,7 @@ void NodePlatform::UnregisterIsolate(IsolateData* isolate_data) { std::shared_ptr<PerIsolatePlatformData> existing = per_isolate_[isolate]; CHECK(existing); if (existing->unref() == 0) { + existing->Shutdown(); per_isolate_.erase(isolate); } } |