Bug 1230768. r=jesup a=sylvestre
authorGian-Carlo Pascutto <gcp@mozilla.com>
Wed, 10 Feb 2016 17:15:28 +0100
changeset 313129 bafc86c12e63
parent 313128 29cc2f417d15
child 313130 905a0a5af413
push id1040
push userraliiev@mozilla.com
push date2016-02-29 17:11 +0000
treeherdermozilla-release@8c3167321162 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, sylvestre
bugs1230768
milestone45.0
Bug 1230768. r=jesup a=sylvestre
dom/media/systemservices/CamerasChild.cpp
--- a/dom/media/systemservices/CamerasChild.cpp
+++ b/dom/media/systemservices/CamerasChild.cpp
@@ -14,16 +14,17 @@
 #include "mozilla/ipc/BackgroundChild.h"
 #include "mozilla/ipc/PBackgroundChild.h"
 #include "mozilla/Logging.h"
 #include "mozilla/SyncRunnable.h"
 #include "mozilla/WeakPtr.h"
 #include "mozilla/unused.h"
 #include "MediaUtils.h"
 #include "nsThreadUtils.h"
+#include "base/singleton.h"
 
 #undef LOG
 #undef LOG_ENABLED
 mozilla::LazyLogModule gCamerasChildLog("CamerasChild");
 #define LOG(args) MOZ_LOG(gCamerasChildLog, mozilla::LogLevel::Debug, args)
 #define LOG_ENABLED() MOZ_LOG_TEST(gCamerasChildLog, mozilla::LogLevel::Debug)
 
 namespace mozilla {
@@ -58,36 +59,33 @@ public:
       mCamerasChildThread(nullptr) {
     LOG(("CamerasSingleton: %p", this));
   }
 
   ~CamerasSingleton() {
     LOG(("~CamerasSingleton: %p", this));
   }
 
-  static CamerasSingleton& GetInstance() {
-    static CamerasSingleton instance;
-    return instance;
-  }
-
   static OffTheBooksMutex& Mutex() {
-    return GetInstance().mCamerasMutex;
+    return gTheInstance.get()->mCamerasMutex;
   }
 
   static CamerasChild*& Child() {
-    GetInstance().Mutex().AssertCurrentThreadOwns();
-    return GetInstance().mCameras;
+    Mutex().AssertCurrentThreadOwns();
+    return gTheInstance.get()->mCameras;
   }
 
   static nsCOMPtr<nsIThread>& Thread() {
-    GetInstance().Mutex().AssertCurrentThreadOwns();
-    return GetInstance().mCamerasChildThread;
+    Mutex().AssertCurrentThreadOwns();
+    return gTheInstance.get()->mCamerasChildThread;
   }
 
 private:
+  static Singleton<CamerasSingleton> gTheInstance;
+
   // Reinitializing CamerasChild will change the pointers below.
   // We don't want this to happen in the middle of preparing IPC.
   // We will be alive on destruction, so this needs to be off the books.
   mozilla::OffTheBooksMutex mCamerasMutex;
 
   // This is owned by the IPC code, and the same code controls the lifetime.
   // It will set and clear this pointer as appropriate in setup/teardown.
   // We'd normally make this a WeakPtr but unfortunately the IPC code already