Bug 1415556 - P4. Make members atomics. r?padenot draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 10 Nov 2017 18:27:39 +0100
changeset 696751 129c1bb2eb3f7e5df024f32d73cbd5217bf7e32e
parent 696750 4f843377d92ca5e592560849dee0ef806ba00082
child 696752 7925479fd30a430459feecfb98dee4d1e723948e
push id88781
push userbmo:jyavenard@mozilla.com
push dateSat, 11 Nov 2017 09:23:59 +0000
Bug 1415556 - P4. Make members atomics. r?padenot They are accessed across multiple threads without the use of monitors. While it could be argued that some use of the monitor in functions accessing those members would set in place memory barriers, making them atomics remove all doubts as to the thread safetyness of their use. MozReview-Commit-ID: tyTqeGgDNM
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -1482,17 +1482,17 @@ bool
 MediaStreamGraphImpl::OneIteration(GraphTime aStateEnd)
   WebCore::DenormalDisabler disabler;
   // Process graph message from the main thread for this iteration.
-  GraphTime stateEnd = std::min(aStateEnd, mEndTime);
+  GraphTime stateEnd = std::min(aStateEnd, GraphTime(mEndTime));
   mStateComputedTime = stateEnd;
   GraphTime oldProcessedTime = mProcessedTime;
   mProcessedTime = stateEnd;
--- a/dom/media/MediaStreamGraphImpl.h
+++ b/dom/media/MediaStreamGraphImpl.h
@@ -6,16 +6,17 @@
 #include "MediaStreamGraph.h"
 #include "AudioMixer.h"
 #include "GraphDriver.h"
 #include "Latency.h"
+#include "mozilla/Atomics.h"
 #include "mozilla/Monitor.h"
 #include "mozilla/Services.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/WeakPtr.h"
 #include "nsDataHashtable.h"
 #include "nsIMemoryReporter.h"
 #include "nsINamed.h"
@@ -728,17 +729,17 @@ public:
    * Modified on the main and graph thread (in UpdateMainThreadState() when
    * we're about to shutdown) in mMonitor. mMonitor must be held when accessed.
   LifecycleState mLifecycleState;
    * The graph should stop processing at or after this time.
    * Only set on main thread. Read on both main and MSG thread.
-  GraphTime mEndTime;
+  Atomic<GraphTime> mEndTime;
    * True when we need to do a forced shutdown during application shutdown.
    * Only set on main thread.
    * Can be read safely on the main thread, on all other threads mMonitor must
    * be held.
   bool mForceShutDown;
@@ -765,17 +766,17 @@ public:
    * processed as an atomic batch.
   nsTArray<UniquePtr<ControlMessage>> mCurrentTaskMessageQueue;
    * True when RunInStableState has determined that mLifecycleState is >
    * LIFECYCLE_RUNNING. Since only the main thread can reset mLifecycleState to
    * LIFECYCLE_RUNNING, this can be relied on to not change unexpectedly.
-  bool mDetectedNotRunning;
+  Atomic<bool> mDetectedNotRunning;
    * True when a stable state runner has been posted to the appshell to run
    * RunInStableState at the next stable state.
    * Only accessed on the main thread.
   bool mPostedRunInStableState;
    * True when processing real-time audio/video.  False when processing non-realtime