Bug 927944 part B - move AutoCriticalSection to nsWindowsHelpers.h and use it instead of manual lock handling in nsWindowsDllBlocklist.cpp, r=ehsan
authorBenjamin Smedberg <benjamin@smedbergs.us>
Fri, 18 Oct 2013 14:24:51 -0400
changeset 165363 e3d6e17ad7a3d8687bd05cc041ef1e80ee154478
parent 165362 d04bbdfff591d7517f8f8cc0f1f51d806a21d4b6
child 165364 9faa8e2237db9e5275f5015126120f33ddc760f2
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs927944
milestone27.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 927944 part B - move AutoCriticalSection to nsWindowsHelpers.h and use it instead of manual lock handling in nsWindowsDllBlocklist.cpp, r=ehsan
toolkit/xre/nsWindowsDllBlocklist.cpp
xpcom/base/nsWindowsHelpers.h
xpcom/ds/TimeStamp_windows.cpp
--- a/toolkit/xre/nsWindowsDllBlocklist.cpp
+++ b/toolkit/xre/nsWindowsDllBlocklist.cpp
@@ -15,16 +15,17 @@
 
 #include "nsAutoPtr.h"
 #include "nsThreadUtils.h"
 
 #include "prlog.h"
 
 #include "nsWindowsDllInterceptor.h"
 #include "mozilla/WindowsVersion.h"
+#include "nsWindowsHelpers.h"
 
 using namespace mozilla;
 
 #ifdef MOZ_CRASHREPORTER
 #include "nsExceptionHandler.h"
 #endif
 
 #define ALL_VERSIONS   ((unsigned long long)-1LL)
@@ -239,32 +240,30 @@ static CRITICAL_SECTION sLock;
  * we roll our own.
  */
 class ReentrancySentinel
 {
 public:
   explicit ReentrancySentinel(const char* dllName)
   {
     DWORD currentThreadId = GetCurrentThreadId();
-    EnterCriticalSection(&sLock);
+    AutoCriticalSection lock(&sLock);
     mPreviousDllName = (*sThreadMap)[currentThreadId];
 
     // If there is a DLL currently being loaded and it has the same name
     // as the current attempt, we're re-entering.
     mReentered = mPreviousDllName && !stricmp(mPreviousDllName, dllName);
     (*sThreadMap)[currentThreadId] = dllName;
-    LeaveCriticalSection(&sLock);
   }
     
   ~ReentrancySentinel()
   {
     DWORD currentThreadId = GetCurrentThreadId();
-    EnterCriticalSection(&sLock);
+    AutoCriticalSection lock(&sLock);
     (*sThreadMap)[currentThreadId] = mPreviousDllName;
-    LeaveCriticalSection(&sLock);
   }
 
   bool BailOut() const
   {
     return mReentered;
   };
     
   static void InitializeStatics()
@@ -311,34 +310,32 @@ private:
   static DllBlockSet* gFirst;
 };
 
 DllBlockSet* DllBlockSet::gFirst;
 
 void
 DllBlockSet::Add(const char* name, unsigned long long version)
 {
-  EnterCriticalSection(&sLock);
+  AutoCriticalSection lock(&sLock);
   for (DllBlockSet* b = gFirst; b; b = b->mNext) {
     if (0 == strcmp(b->mName, name) && b->mVersion == version) {
-      LeaveCriticalSection(&sLock);
       return;
     }
   }
   // Not already present
   DllBlockSet* n = new DllBlockSet(name, version);
   n->mNext = gFirst;
   gFirst = n;
-  LeaveCriticalSection(&sLock);
 }
 
 void
 DllBlockSet::Write(HANDLE file)
 {
-  EnterCriticalSection(&sLock);
+  AutoCriticalSection lock(&sLock);
   DWORD nBytes;
 
   // Because this method is called after a crash occurs, and uses heap memory,
   // protect this entire block with a structured exception handler.
   __try {
     for (DllBlockSet* b = gFirst; b; b = b->mNext) {
       // write name[,v.v.v.v];
       WriteFile(file, b->mName, strlen(b->mName), &nBytes, nullptr);
@@ -357,18 +354,16 @@ DllBlockSet::Write(HANDLE file)
             WriteFile(file, ".", 1, &nBytes, nullptr);
           }
         }
       }
       WriteFile(file, ";", 1, &nBytes, nullptr);
     }
   }
   __except (EXCEPTION_EXECUTE_HANDLER) { }
-
-  LeaveCriticalSection(&sLock);
 }
 
 static
 wchar_t* getFullPath (PWCHAR filePath, wchar_t* fname)
 {
   // In Windows 8, the first parameter seems to be used for more than just the
   // path name.  For example, its numerical value can be 1.  Passing a non-valid
   // pointer to SearchPathW will cause a crash, so we need to check to see if we
--- a/xpcom/base/nsWindowsHelpers.h
+++ b/xpcom/base/nsWindowsHelpers.h
@@ -4,16 +4,36 @@
 
 #ifndef nsWindowsHelpers_h
 #define nsWindowsHelpers_h
 
 #include <windows.h>
 #include "nsAutoRef.h"
 #include "nscore.h"
 
+// ----------------------------------------------------------------------------
+// Critical Section helper class
+// ----------------------------------------------------------------------------
+
+class AutoCriticalSection
+{
+public:
+  AutoCriticalSection(LPCRITICAL_SECTION section)
+    : mSection(section)
+  {
+    ::EnterCriticalSection(mSection);
+  }
+  ~AutoCriticalSection()
+  {
+    ::LeaveCriticalSection(mSection);
+  }
+private:
+  LPCRITICAL_SECTION mSection;
+};
+
 template<>
 class nsAutoRefTraits<HKEY>
 {
 public:
   typedef HKEY RawRef;
   static HKEY Void()
   {
     return nullptr;
--- a/xpcom/ds/TimeStamp_windows.cpp
+++ b/xpcom/ds/TimeStamp_windows.cpp
@@ -9,16 +9,17 @@
 
 // XXX Forcing log to be able to catch issues in the field.  Should be removed
 // before this reaches the Release or even Beta channel.
 #define FORCE_PR_LOG
 
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/TimeStamp.h"
+#include "nsWindowsHelpers.h"
 #include <windows.h>
 
 #include "nsCRT.h"
 #include "prlog.h"
 #include "prprf.h"
 #include <stdio.h>
 
 #include <intrin.h>
@@ -180,36 +181,16 @@ static DWORD sLastGTCResult = 0;
 // incremented atomically.
 static DWORD sLastGTCRollover = 0;
 
 namespace mozilla {
 
 typedef ULONGLONG (WINAPI* GetTickCount64_t)();
 static GetTickCount64_t sGetTickCount64 = nullptr;
 
-// ----------------------------------------------------------------------------
-// Critical Section helper class
-// ----------------------------------------------------------------------------
-
-class AutoCriticalSection
-{
-public:
-  AutoCriticalSection(LPCRITICAL_SECTION section)
-    : mSection(section)
-  {
-    ::EnterCriticalSection(mSection);
-  }
-  ~AutoCriticalSection()
-  {
-    ::LeaveCriticalSection(mSection);
-  }
-private:
-  LPCRITICAL_SECTION mSection;
-};
-
 // Function protecting GetTickCount result from rolling over,
 // result is in [ms]
 static ULONGLONG WINAPI
 MozGetTickCount64()
 {
   DWORD GTC = ::GetTickCount();
 
   // Cheaper then CMPXCHG8B