summaryrefslogtreecommitdiffstats
path: root/js/src/threading/windows/MutexImpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/threading/windows/MutexImpl.cpp')
-rw-r--r--js/src/threading/windows/MutexImpl.cpp47
1 files changed, 3 insertions, 44 deletions
diff --git a/js/src/threading/windows/MutexImpl.cpp b/js/src/threading/windows/MutexImpl.cpp
index 385d1c8de..e838459b5 100644
--- a/js/src/threading/windows/MutexImpl.cpp
+++ b/js/src/threading/windows/MutexImpl.cpp
@@ -13,35 +13,6 @@
#include "threading/Mutex.h"
#include "threading/windows/MutexPlatformData.h"
-namespace {
-
-// We build with a toolkit that supports WinXP, so we have to probe
-// for modern features at runtime. This is necessary because Vista and
-// later automatically allocate and subsequently leak a debug info
-// object for each critical section that we allocate unless we tell it
-// not to. In order to tell it not to, we need the extra flags field
-// provided by the Ex version of InitializeCriticalSection.
-struct MutexNativeImports
-{
- using InitializeCriticalSectionExT = BOOL (WINAPI*)(CRITICAL_SECTION*, DWORD, DWORD);
- InitializeCriticalSectionExT InitializeCriticalSectionEx;
-
- MutexNativeImports() {
- HMODULE kernel32_dll = GetModuleHandle("kernel32.dll");
- MOZ_RELEASE_ASSERT(kernel32_dll != NULL);
- InitializeCriticalSectionEx = reinterpret_cast<InitializeCriticalSectionExT>(
- GetProcAddress(kernel32_dll, "InitializeCriticalSectionEx"));
- }
-
- bool hasInitializeCriticalSectionEx() const {
- return InitializeCriticalSectionEx;
- }
-};
-
-static MutexNativeImports NativeImports;
-
-} // (anonymous namespace)
-
js::detail::MutexImpl::MutexImpl()
{
AutoEnterOOMUnsafeRegion oom;
@@ -49,18 +20,7 @@ js::detail::MutexImpl::MutexImpl()
if (!platformData_)
oom.crash("js::Mutex::Mutex");
- // This number was adopted from NSPR.
- const static DWORD LockSpinCount = 1500;
- BOOL r;
- if (NativeImports.hasInitializeCriticalSectionEx()) {
- r = NativeImports.InitializeCriticalSectionEx(&platformData()->criticalSection,
- LockSpinCount,
- CRITICAL_SECTION_NO_DEBUG_INFO);
- } else {
- r = InitializeCriticalSectionAndSpinCount(&platformData()->criticalSection,
- LockSpinCount);
- }
- MOZ_RELEASE_ASSERT(r);
+ InitializeSRWLock(&platformData()->lock);
}
js::detail::MutexImpl::~MutexImpl()
@@ -68,18 +28,17 @@ js::detail::MutexImpl::~MutexImpl()
if (!platformData_)
return;
- DeleteCriticalSection(&platformData()->criticalSection);
js_delete(platformData());
}
void
js::detail::MutexImpl::lock()
{
- EnterCriticalSection(&platformData()->criticalSection);
+ AcquireSRWLockExclusive(&platformData()->lock);
}
void
js::detail::MutexImpl::unlock()
{
- LeaveCriticalSection(&platformData()->criticalSection);
+ ReleaseSRWLockExclusive(&platformData()->lock);
}