Bug 1534238 - Initialize GraphRunner::mThread last. r=padenot
authorAndreas Pehrson <apehrson@mozilla.com>
Mon, 11 Mar 2019 13:18:04 +0000
changeset 524377 b015322cb7795419db78fe072e3b56d7106b8e0e
parent 524376 5a14eec92d6e422f452505dbffbf84862fc74af9
child 524378 ee2473319e97f98373b68151353b4de5e2cfc2c3
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1534238
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1534238 - Initialize GraphRunner::mThread last. r=padenot The thread may pre-empt the thread running the ctor and launch GraphRunner::Run with uninitialized members. This patch ensures they are initialized first. Differential Revision: https://phabricator.services.mozilla.com/D22963
dom/media/GraphRunner.cpp
dom/media/GraphRunner.h
--- a/dom/media/GraphRunner.cpp
+++ b/dom/media/GraphRunner.cpp
@@ -18,16 +18,22 @@ namespace mozilla {
 static void Start(void* aArg) {
   GraphRunner* th = static_cast<GraphRunner*>(aArg);
   th->Run();
 }
 
 GraphRunner::GraphRunner(MediaStreamGraphImpl* aGraph)
     : mMonitor("GraphRunner::mMonitor"),
       mGraph(aGraph),
+      mStateEnd(0),
+      mStillProcessing(true),
+      mShutdown(false),
+      mStarted(false),
+      // Note that mThread needs to be initialized last, as it may pre-empt the
+      // thread running this ctor and enter Run() with uninitialized members.
       mThread(PR_CreateThread(PR_SYSTEM_THREAD, &Start, this,
                               PR_PRIORITY_URGENT, PR_GLOBAL_THREAD,
                               PR_JOINABLE_THREAD, 0)) {
   MOZ_COUNT_CTOR(GraphRunner);
 }
 
 GraphRunner::~GraphRunner() {
   MOZ_COUNT_DTOR(GraphRunner);
--- a/dom/media/GraphRunner.h
+++ b/dom/media/GraphRunner.h
@@ -55,28 +55,28 @@ class GraphRunner {
 
  private:
   // Monitor used for yielding mThread through Wait(), and scheduling mThread
   // through Signal() from a GraphDriver.
   Monitor mMonitor;
   // The MediaStreamGraph we're running. Weakptr beecause this graph owns us and
   // guarantees that our lifetime will not go beyond that of itself.
   MediaStreamGraphImpl* const mGraph;
-  // The thread running mGraph.
-  PRThread* const mThread;
   // GraphTime being handed over to the graph through OneIteration. Protected by
   // mMonitor.
-  GraphTime mStateEnd = 0;
+  GraphTime mStateEnd;
   // Reply from mGraph's OneIteration. Protected by mMonitor.
-  bool mStillProcessing = true;
+  bool mStillProcessing;
   // True after Shutdown(). Protected by mMonitor.
-  bool mShutdown = false;
+  bool mShutdown;
   // True after mThread has started running and has entered its main loop.
   // Protected by mMonitor.
-  bool mStarted = false;
+  bool mStarted;
+  // The thread running mGraph.
+  PRThread* const mThread;
 
 #ifdef DEBUG
   // Set to mGraph's audio callback driver's thread id, if run by an
   // AudioCallbackDriver, while OneIteration() is running.
   std::thread::id mAudioDriverThreadId = std::thread::id();
   // Set to mGraph's system clock driver's thread, if run by a
   // SystemClockDriver, while OneIteration() is running.
   nsIThread* mClockDriverThread = nullptr;