diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-03-01 23:35:54 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-03-13 00:12:56 +0000 |
commit | 6d9aa73b1f2a0b053e39d743b1ddf382d35adfad (patch) | |
tree | 3254de3bb6292f36c4458f06f28a663614df924f /src/node_worker.cc | |
parent | 377c5835e8bfcd04273f24a244b2ba4aff76a27c (diff) | |
download | android-node-v8-6d9aa73b1f2a0b053e39d743b1ddf382d35adfad.tar.gz android-node-v8-6d9aa73b1f2a0b053e39d743b1ddf382d35adfad.tar.bz2 android-node-v8-6d9aa73b1f2a0b053e39d743b1ddf382d35adfad.zip |
src: clean up MultiIsolatePlatform interface
- Since this was introduced, V8 has effectively started requiring
that the platform knows of the `Isolate*` before we (or an embedder)
create our `IsolateData` structure; therefore, (un)registering it
from the `IsolateData` constructor/destructor doesn’t make much
sense anymore.
- Instead, we can require that the register/unregister functions
are only called once, simplifying the implementation a bit.
- Add a callback that we can use to know when the platform has
cleaned up its resources associated with a given `Isolate`.
In particular, this means that in the Worker code, we don’t need
to rely on what are essentially guesses about the number of event
loop turns that we need in order to have everything cleaned up.
PR-URL: https://github.com/nodejs/node/pull/26384
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/node_worker.cc')
-rw-r--r-- | src/node_worker.cc | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/node_worker.cc b/src/node_worker.cc index 6f290c3e2a..42d407e654 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -188,16 +188,20 @@ class WorkerThreadData { w_->platform_->CancelPendingDelayedTasks(isolate); + bool platform_finished = false; + isolate_data_.reset(); + + w_->platform_->AddIsolateFinishedCallback(isolate, [](void* data) { + *static_cast<bool*>(data) = true; + }, &platform_finished); w_->platform_->UnregisterIsolate(isolate); isolate->Dispose(); - // Need to run the loop twice more to close the platform's uv_async_t - // TODO(addaleax): It would be better for the platform itself to provide - // some kind of notification when it has fully cleaned up. - uv_run(&loop_, UV_RUN_ONCE); - uv_run(&loop_, UV_RUN_ONCE); + // Wait until the platform has cleaned up all relevant resources. + while (!platform_finished) + uv_run(&loop_, UV_RUN_ONCE); CheckedUvLoopClose(&loop_); } |