Skip to content

Commit 7a02118

Browse files
liamappelbecommit-bot@chromium.org
authored andcommitted
[vm/fuchsia]: Safely shutdown the async message loop.
Shut down the message loop before destroying it, and also clear the default dispatcher. Bug: https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=59293 Change-Id: I77ba07f4139309e70f812cd4f921e6af4bdc4957 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161462 Reviewed-by: Zach Anderson <[email protected]> Commit-Queue: Liam Appelbe <[email protected]>
1 parent 334d368 commit 7a02118

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

runtime/vm/os_fuchsia.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ void OS::PrintErr(const char* format, ...) {
353353
}
354354

355355
void OS::Init() {
356-
if (async_get_default_dispatcher() == NULL) {
356+
if (async_get_default_dispatcher() == nullptr) {
357357
async_loop_create(&kAsyncLoopConfigAttachToCurrentThread, &message_loop);
358358
async_set_default_dispatcher(async_loop_get_dispatcher(message_loop));
359359
async_loop_start_thread(message_loop, "Fuchsia async loop", nullptr);
@@ -368,9 +368,19 @@ void OS::Init() {
368368
}
369369

370370
void OS::Cleanup() {
371+
if (message_loop != nullptr) {
372+
async_loop_shutdown(message_loop);
373+
}
374+
371375
metrics = nullptr;
372376
component_inspector = nullptr;
377+
373378
if (message_loop != nullptr) {
379+
// Check message_loop is still the default dispatcher before clearing it.
380+
if (async_get_default_dispatcher() ==
381+
async_loop_get_dispatcher(message_loop)) {
382+
async_set_default_dispatcher(nullptr);
383+
}
374384
async_loop_destroy(message_loop);
375385
message_loop = nullptr;
376386
}

0 commit comments

Comments
 (0)