Bug 1164374 - Use StaticMutex in BrowserProcessSubThread. r=froydnj.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 13 May 2015 01:59:52 -0700
changeset 246128 e42b59217f3d2fd7d59886751615cfb827c8dba2
parent 246127 8842010aeab4e5382ea20d44d540bf700866bb18
child 246129 0d4659ab6d49c34087610dc813798b119af5f5c1
push id60372
push usernnethercote@mozilla.com
push dateFri, 29 May 2015 00:12:24 +0000
treeherdermozilla-inbound@e42b59217f3d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1164374
milestone41.0a1
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 1164374 - Use StaticMutex in BrowserProcessSubThread. r=froydnj. This removes a static constructor.
ipc/glue/BrowserProcessSubThread.cpp
ipc/glue/BrowserProcessSubThread.h
--- a/ipc/glue/BrowserProcessSubThread.cpp
+++ b/ipc/glue/BrowserProcessSubThread.cpp
@@ -25,42 +25,43 @@ static const char* kBrowserThreadNames[B
 //  "Chrome_FileThread",  // FILE
 //  "Chrome_DBThread",  // DB
 //  "Chrome_HistoryThread",  // HISTORY
 #if defined(OS_LINUX)
   "Gecko_Background_X11Thread",  // BACKGROUND_X11
 #endif
 };
 
-Lock BrowserProcessSubThread::sLock;
+/* static */ StaticMutex BrowserProcessSubThread::sLock;
 BrowserProcessSubThread* BrowserProcessSubThread::sBrowserThreads[ID_COUNT] = {
   nullptr,  // IO
 //  nullptr,  // FILE
 //  nullptr,  // DB
 //  nullptr,  // HISTORY
 #if defined(OS_LINUX)
   nullptr,  // BACKGROUND_X11
 #endif
 };
 
 BrowserProcessSubThread::BrowserProcessSubThread(ID aId) :
   base::Thread(kBrowserThreadNames[aId]),
   mIdentifier(aId),
   mNotificationService(nullptr)
 {
-  AutoLock lock(sLock);
+  StaticMutexAutoLock lock(sLock);
   DCHECK(aId >= 0 && aId < ID_COUNT);
   DCHECK(sBrowserThreads[aId] == nullptr);
   sBrowserThreads[aId] = this;
 }
 
 BrowserProcessSubThread::~BrowserProcessSubThread()
 {
   Stop();
-  {AutoLock lock(sLock);
+  {
+    StaticMutexAutoLock lock(sLock);
     sBrowserThreads[mIdentifier] = nullptr;
   }
 
 }
 
 void
 BrowserProcessSubThread::Init()
 {
@@ -83,17 +84,17 @@ BrowserProcessSubThread::CleanUp()
   CoUninitialize();
 #endif
 }
 
 // static
 MessageLoop*
 BrowserProcessSubThread::GetMessageLoop(ID aId)
 {
-  AutoLock lock(sLock);
+  StaticMutexAutoLock lock(sLock);
   DCHECK(aId >= 0 && aId < ID_COUNT);
 
   if (sBrowserThreads[aId])
     return sBrowserThreads[aId]->message_loop();
 
   return nullptr;
 }
 
--- a/ipc/glue/BrowserProcessSubThread.h
+++ b/ipc/glue/BrowserProcessSubThread.h
@@ -4,17 +4,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_ipc_BrowserProcessSubThread_h
 #define mozilla_ipc_BrowserProcessSubThread_h
 
 #include "base/thread.h"
-#include "base/lock.h"
+#include "mozilla/StaticMutex.h"
 
 #include "nsDebug.h"
 
 class NotificationService;
 
 namespace mozilla {
 namespace ipc {
 
@@ -55,19 +55,17 @@ private:
   // identifier at a given time.
   ID mIdentifier;
 
   NotificationService* mNotificationService;
 
   // This lock protects |browser_threads_|.  Do not read or modify that array
   // without holding this lock.  Do not block while holding this lock.
 
-  // FIXME/cjones: XPCOM doesn't like static vars, so can't use 
-  // mozilla::Mutex
-  static Lock sLock;
+  static StaticMutex sLock;
 
   // An array of the ChromeThread objects.  This array is protected by |lock_|.
   // The threads are not owned by this array.  Typically, the threads are owned
   // on the UI thread by the g_browser_process object.  ChromeThreads remove
   // themselves from this array upon destruction.
   static BrowserProcessSubThread* sBrowserThreads[ID_COUNT];
 };