Bug 1534238 - Initialize GraphRunner::mThread last. r=padenot
authorAndreas Pehrson <apehrson@mozilla.com>
Mon, 11 Mar 2019 13:18:04 +0000
changeset 521379 b015322cb779
parent 521378 5a14eec92d6e
child 521380 ee2473319e97
push id10866
push usernerli@mozilla.com
push dateTue, 12 Mar 2019 18:59:09 +0000
treeherdermozilla-beta@445c24a51727 [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;