Bug 1407810 - Make DecoderDoctorLogger::sLogState 'ReleaseAcquire' - r=jwwang draft
authorGerald Squelart <gsquelart@mozilla.com>
Thu, 12 Oct 2017 10:45:03 +1100
changeset 708712 475b32f76d9660d03333047eb7e7add62b717a79
parent 708706 4b94da21a9e6171f9911ffad171af23c26e6227b
child 708713 38de1f6ce8a404e2ccc1591392176151edc8d078
push id92413
push usergsquelart@mozilla.com
push dateWed, 06 Dec 2017 23:54:05 +0000
reviewersjwwang
bugs1407810
milestone59.0a1
Bug 1407810 - Make DecoderDoctorLogger::sLogState 'ReleaseAcquire' - r=jwwang sLogState is accessed at least once for every DDLog call, even when logging is disabled, so we want it to be as quick as possible for minimal impact on most users. MozReview-Commit-ID: AMstgXmixrv
dom/media/doctor/DecoderDoctorLogger.cpp
dom/media/doctor/DecoderDoctorLogger.h
--- a/dom/media/doctor/DecoderDoctorLogger.cpp
+++ b/dom/media/doctor/DecoderDoctorLogger.cpp
@@ -9,17 +9,17 @@
 #include "DDLogUtils.h"
 #include "DDMediaLogs.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/SystemGroup.h"
 #include "mozilla/Unused.h"
 
 namespace mozilla {
 
-/* static */ Atomic<DecoderDoctorLogger::LogState>
+/* static */ Atomic<DecoderDoctorLogger::LogState, ReleaseAcquire>
   DecoderDoctorLogger::sLogState{ DecoderDoctorLogger::scDisabled };
 
 /* static */ const char* DecoderDoctorLogger::sShutdownReason = nullptr;
 
 static DDMediaLogs* sMediaLogs;
 
 // First DDLogShutdowner sets sLogState to scShutdown, to prevent further
 // logging.
--- a/dom/media/doctor/DecoderDoctorLogger.h
+++ b/dom/media/doctor/DecoderDoctorLogger.h
@@ -341,17 +341,19 @@ private:
   // Currently enabled (logging happens), may be shutdown.
   static constexpr LogState scEnabled = 1;
   // Still disabled, but one thread is working on enabling it, nobody else
   // should interfere during this time.
   static constexpr LogState scEnabling = 2;
   // Shutdown, cannot be re-enabled.
   static constexpr LogState scShutdown = 3;
   // Current state.
-  static Atomic<LogState> sLogState;
+  // "ReleaseAcquire" because when changing to scEnabled, the just-created
+  // sMediaLogs must be accessible to consumers that see scEnabled.
+  static Atomic<LogState, ReleaseAcquire> sLogState;
 
   // If non-null, reason for an abnormal shutdown.
   static const char* sShutdownReason;
 };
 
 // Base class to automatically record a class lifetime. Usage:
 //   class SomeClass : public DecoderDoctorLifeLogger<SomeClass>
 //   {