Bug 927944 part B - move AutoCriticalSection to nsWindowsHelpers.h and use it instead of manual lock handling in nsWindowsDllBlocklist.cpp, r=ehsan

--HG--
extra : rebase_source : 54e55b729263bffbb5a92c3336eacf248e99a659
This commit is contained in:
Benjamin Smedberg 2013-10-18 14:24:51 -04:00
parent b5399b893f
commit 640d851717
3 changed files with 26 additions and 30 deletions

View File

@ -20,6 +20,7 @@
#include "nsWindowsDllInterceptor.h"
#include "mozilla/WindowsVersion.h"
#include "nsWindowsHelpers.h"
using namespace mozilla;
@ -244,22 +245,20 @@ 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
@ -316,10 +315,9 @@ 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;
}
}
@ -327,13 +325,12 @@ DllBlockSet::Add(const char* name, unsigned long long version)
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,
@ -362,8 +359,6 @@ DllBlockSet::Write(HANDLE file)
}
}
__except (EXCEPTION_EXECUTE_HANDLER) { }
LeaveCriticalSection(&sLock);
}
static

View File

@ -9,6 +9,26 @@
#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>
{

View File

@ -14,6 +14,7 @@
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Mutex.h"
#include "mozilla/TimeStamp.h"
#include "nsWindowsHelpers.h"
#include <windows.h>
#include "nsCRT.h"
@ -185,26 +186,6 @@ 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