Bug 1364624 - Switch from CRITICALSECTION to SRWLOCK. r=froydnj a=lizzard
☠☠ backed out by e30deae7bb94 ☠ ☠
authorEric Rahm <erahm@mozilla.com>
Mon, 23 Apr 2018 10:45:20 -0700
changeset 789607 e21076f36898f0677d2e9026dd1df5115d0b46ba
parent 789606 7e263f872c41db36522026d5c5d4e35d767e5d9e
child 789608 bda9a66dc3583e484c42c77089160a2af9441a0b
push id108293
push usernthomas@mozilla.com
push dateMon, 30 Apr 2018 01:46:46 +0000
reviewersfroydnj, lizzard
bugs1364624
milestone60.0
Bug 1364624 - Switch from CRITICALSECTION to SRWLOCK. r=froydnj a=lizzard
mozglue/misc/ConditionVariable_windows.cpp
mozglue/misc/MutexPlatformData_windows.h
mozglue/misc/Mutex_windows.cpp
--- a/mozglue/misc/ConditionVariable_windows.cpp
+++ b/mozglue/misc/ConditionVariable_windows.cpp
@@ -49,38 +49,38 @@ void
 mozilla::detail::ConditionVariableImpl::notify_all()
 {
   WakeAllConditionVariable(&platformData()->cv_);
 }
 
 void
 mozilla::detail::ConditionVariableImpl::wait(MutexImpl& lock)
 {
-  CRITICAL_SECTION* cs = &lock.platformData()->criticalSection;
-  bool r = SleepConditionVariableCS(&platformData()->cv_, cs, INFINITE);
+  SRWLOCK* srwlock = &lock.platformData()->lock;
+  bool r = SleepConditionVariableSRW(&platformData()->cv_, srwlock, INFINITE, 0);
   MOZ_RELEASE_ASSERT(r);
 }
 
 mozilla::detail::CVStatus
 mozilla::detail::ConditionVariableImpl::wait_for(MutexImpl& lock,
                                                  const mozilla::TimeDuration& rel_time)
 {
-  CRITICAL_SECTION* cs = &lock.platformData()->criticalSection;
+  SRWLOCK* srwlock = &lock.platformData()->lock;
 
   // Note that DWORD is unsigned, so we have to be careful to clamp at 0.
   // If rel_time is Forever, then ToMilliseconds is +inf, which evaluates as
   // greater than UINT32_MAX, resulting in the correct INFINITE wait.
   double msecd = rel_time.ToMilliseconds();
   DWORD msec = msecd < 0.0
                ? 0
                : msecd > UINT32_MAX
                  ? INFINITE
                  : static_cast<DWORD>(msecd);
 
-  BOOL r = SleepConditionVariableCS(&platformData()->cv_, cs, msec);
+  BOOL r = SleepConditionVariableSRW(&platformData()->cv_, srwlock, msec, 0);
   if (r)
     return CVStatus::NoTimeout;
   MOZ_RELEASE_ASSERT(GetLastError() == ERROR_TIMEOUT);
   return CVStatus::Timeout;
 }
 
 mozilla::detail::ConditionVariableImpl::~ConditionVariableImpl()
 {
--- a/mozglue/misc/MutexPlatformData_windows.h
+++ b/mozglue/misc/MutexPlatformData_windows.h
@@ -8,12 +8,12 @@
 #define MutexPlatformData_windows_h
 
 #include <windows.h>
 
 #include "mozilla/PlatformMutex.h"
 
 struct mozilla::detail::MutexImpl::PlatformData
 {
-  CRITICAL_SECTION criticalSection;
+  SRWLOCK lock;
 };
 
 #endif // MutexPlatformData_windows_h
--- a/mozglue/misc/Mutex_windows.cpp
+++ b/mozglue/misc/Mutex_windows.cpp
@@ -9,48 +9,33 @@
 #include "mozilla/PlatformMutex.h"
 
 #include <windows.h>
 
 #include "MutexPlatformData_windows.h"
 
 mozilla::detail::MutexImpl::MutexImpl()
 {
-  // This number was adopted from NSPR.
-  const static DWORD LockSpinCount = 1500;
-
-#if defined(RELEASE_OR_BETA)
-  // Vista and later automatically allocate and subsequently leak a debug info
-  // object for each critical section that we allocate unless we tell the
-  // system not to do that.
-  DWORD flags = CRITICAL_SECTION_NO_DEBUG_INFO;
-#else
-  DWORD flags = 0;
-#endif // defined(RELEASE_OR_BETA)
-
-  BOOL r = InitializeCriticalSectionEx(&platformData()->criticalSection,
-                                       LockSpinCount, flags);
-  MOZ_RELEASE_ASSERT(r);
+  InitializeSRWLock(&platformData()->lock);
 }
 
 mozilla::detail::MutexImpl::~MutexImpl()
 {
-  DeleteCriticalSection(&platformData()->criticalSection);
 }
 
 void
 mozilla::detail::MutexImpl::lock()
 {
-  EnterCriticalSection(&platformData()->criticalSection);
+  AcquireSRWLockExclusive(&platformData()->lock);
 }
 
 void
 mozilla::detail::MutexImpl::unlock()
 {
-  LeaveCriticalSection(&platformData()->criticalSection);
+  ReleaseSRWLockExclusive(&platformData()->lock);
 }
 
 mozilla::detail::MutexImpl::PlatformData*
 mozilla::detail::MutexImpl::platformData()
 {
   static_assert(sizeof(platformData_) >= sizeof(PlatformData),
                 "platformData_ is too small");
   return reinterpret_cast<PlatformData*>(platformData_);