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
--- 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>
// {