Bug 1495871 - use C++11 statics in CamerasChild; r=jesup
authorNathan Froyd <froydnj@mozilla.com>
Fri, 05 Oct 2018 13:43:47 -0400
changeset 498322 cdd41eaece0f8c55fe2f32740e1f0b292928c071
parent 498321 2296a2feb192ccf56f118999e1a6ec9fa9f36a34
child 498323 6fc7db6d7326789e53cc0c82189f2196f56e78ca
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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 1495871 - use C++11 statics in CamerasChild; r=jesup C++11 provides guaranteed thread-safe static initialization, so we can use that instead of ipc's baroque Singleton class.
--- a/dom/media/systemservices/CamerasChild.h
+++ b/dom/media/systemservices/CamerasChild.h
@@ -9,17 +9,16 @@
 #include "mozilla/Move.h"
 #include "mozilla/Pair.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/camera/PCamerasChild.h"
 #include "mozilla/camera/PCamerasParent.h"
 #include "mozilla/media/DeviceChangeCallback.h"
 #include "mozilla/Mutex.h"
-#include "base/singleton.h"
 #include "nsCOMPtr.h"
 // conflicts with #include of scoped_ptr.h
 #undef FF
 #include "webrtc/modules/video_capture/video_capture_defines.h"
 namespace mozilla {
@@ -65,48 +64,51 @@ template <class T> class LockAndDispatch
 // async messaging. We dispatch the messages to another thread to send them
 // async and hold a Monitor to wait for the result to be asynchronously received
 // again. The requirement for async messaging originates on the parent side:
 // it's not reasonable to block all PBackground IPC there while waiting for
 // something like device enumeration to complete.
 class CamerasSingleton {
-  CamerasSingleton();
-  ~CamerasSingleton();
   static OffTheBooksMutex& Mutex() {
-    return Singleton<mozilla::camera::CamerasSingleton>::get()->mCamerasMutex;
+    return singleton().mCamerasMutex;
   static CamerasChild*& Child() {
-    return Singleton<mozilla::camera::CamerasSingleton>::get()->mCameras;
+    return singleton().mCameras;
   static nsCOMPtr<nsIThread>& Thread() {
-    return Singleton<mozilla::camera::CamerasSingleton>::get()->mCamerasChildThread;
+    return singleton().mCamerasChildThread;
   static nsCOMPtr<nsIThread>& FakeDeviceChangeEventThread() {
-    return Singleton<mozilla::camera::CamerasSingleton>::get()->mFakeDeviceChangeEventThread;
+    return singleton().mFakeDeviceChangeEventThread;
   static bool InShutdown() {
-    return gTheInstance.get()->mInShutdown;
+    return singleton().mInShutdown;
   static void StartShutdown() {
-    gTheInstance.get()->mInShutdown = true;
+    singleton().mInShutdown = true;
-  static Singleton<CamerasSingleton> gTheInstance;
+  CamerasSingleton();
+  ~CamerasSingleton();
+  static CamerasSingleton& singleton() {
+    static CamerasSingleton camera;
+    return camera;
+  }
   // 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.