From 382bffd9a0e7457688f5e470ce641dec8b3271c3 Mon Sep 17 00:00:00 2001 From: Karl Tomlinson Date: Wed, 17 Aug 2022 21:33:16 +0000 Subject: [PATCH] Bug 1752305 AsyncShutdown() MediaTrackGrph thread r=padenot This avoids putting a nested event loop on the stack, which may not unwind if further threads are shutdown, leading to stack exhaustion. GraphDriver::Shutdown() is called only after control of the graph has been handed to the main thread so the graph is not running while this is called and so MediaTrackGraphShutDownRunnable on the main thread should not need to wait for thread shutdown. Differential Revision: https://phabricator.services.mozilla.com/D151357 --- dom/media/GraphDriver.cpp | 4 ++-- dom/media/GraphDriver.h | 2 +- dom/media/MediaTrackGraph.cpp | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/dom/media/GraphDriver.cpp b/dom/media/GraphDriver.cpp index 588a133d8235..e37cb37f3709 100644 --- a/dom/media/GraphDriver.cpp +++ b/dom/media/GraphDriver.cpp @@ -83,7 +83,7 @@ class MediaTrackGraphShutdownThreadRunnable : public Runnable { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(mThread); - mThread->Shutdown(); + mThread->AsyncShutdown(); mThread = nullptr; return NS_OK; } @@ -154,7 +154,7 @@ void ThreadedDriver::Shutdown() { if (mThread) { LOG(LogLevel::Debug, ("%p: Stopping ThreadedDriver's %p thread", Graph(), this)); - mThread->Shutdown(); + mThread->AsyncShutdown(); mThread = nullptr; } } diff --git a/dom/media/GraphDriver.h b/dom/media/GraphDriver.h index 539d9bd10dae..0180c6a5dced 100644 --- a/dom/media/GraphDriver.h +++ b/dom/media/GraphDriver.h @@ -275,7 +275,7 @@ class GraphDriver { * A driver cannot be started twice, it must be shutdown * before being started again. */ virtual void Start() = 0; - /* Shutdown GraphDriver (synchronously) */ + /* Shutdown GraphDriver */ MOZ_CAN_RUN_SCRIPT virtual void Shutdown() = 0; /* Rate at which the GraphDriver runs, in ms. This can either be user * controlled (because we are using a {System,Offline}ClockDriver, and decide diff --git a/dom/media/MediaTrackGraph.cpp b/dom/media/MediaTrackGraph.cpp index ba1e4f8ff968..fae5047ee2fd 100644 --- a/dom/media/MediaTrackGraph.cpp +++ b/dom/media/MediaTrackGraph.cpp @@ -1737,8 +1737,6 @@ class MediaTrackGraphShutDownRunnable : public Runnable { RefPtr(mGraph->mGraphRunner)->Shutdown(); } - // This will wait until it's shutdown since - // we'll start tearing down the graph after this RefPtr(mGraph->mDriver)->Shutdown(); // Release the driver now so that an AudioCallbackDriver will release its -- 2.11.4.GIT