Bug 1371435 - Backed out changeset 5b6d169feb92. r=froydnj
authorEric Rahm <erahm@mozilla.com>
Wed, 28 Jun 2017 13:56:57 -0700
changeset 366446 8c69b1e4d5a62688ac69657f926683adc04e8312
parent 366445 0d961ec8015a554cc252dfe7611174fc96b2de8b
child 366447 d95016c5fc991c075d10b4591491d50650a7c487
push id91974
push usererahm@mozilla.com
push dateWed, 28 Jun 2017 22:26:30 +0000
treeherdermozilla-inbound@8c69b1e4d5a6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1371435
milestone56.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 1371435 - Backed out changeset 5b6d169feb92. r=froydnj CRITICAL_SECTIONs have useful debug info that we'd like to keep around at least on nightly, rather than having diverging signatures on crash stats we'd like to just keep a unified implementation. As we didn't see significant perf improvements after landing we're going to just back this out.
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)
 {
-  SRWLOCK* srwlock = &lock.platformData()->lock;
-  bool r = SleepConditionVariableSRW(&platformData()->cv_, srwlock, INFINITE, 0);
+  CRITICAL_SECTION* cs = &lock.platformData()->criticalSection;
+  bool r = SleepConditionVariableCS(&platformData()->cv_, cs, INFINITE);
   MOZ_RELEASE_ASSERT(r);
 }
 
 mozilla::detail::CVStatus
 mozilla::detail::ConditionVariableImpl::wait_for(MutexImpl& lock,
                                                  const mozilla::TimeDuration& rel_time)
 {
-  SRWLOCK* srwlock = &lock.platformData()->lock;
+  CRITICAL_SECTION* cs = &lock.platformData()->criticalSection;
 
   // 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 = SleepConditionVariableSRW(&platformData()->cv_, srwlock, msec, 0);
+  BOOL r = SleepConditionVariableCS(&platformData()->cv_, cs, msec);
   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
 {
-  SRWLOCK lock;
+  CRITICAL_SECTION criticalSection;
 };
 
 #endif // MutexPlatformData_windows_h
--- a/mozglue/misc/Mutex_windows.cpp
+++ b/mozglue/misc/Mutex_windows.cpp
@@ -9,33 +9,48 @@
 #include "mozilla/PlatformMutex.h"
 
 #include <windows.h>
 
 #include "MutexPlatformData_windows.h"
 
 mozilla::detail::MutexImpl::MutexImpl()
 {
-  InitializeSRWLock(&platformData()->lock);
+  // 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);
 }
 
 mozilla::detail::MutexImpl::~MutexImpl()
 {
+  DeleteCriticalSection(&platformData()->criticalSection);
 }
 
 void
 mozilla::detail::MutexImpl::lock()
 {
-  AcquireSRWLockExclusive(&platformData()->lock);
+  EnterCriticalSection(&platformData()->criticalSection);
 }
 
 void
 mozilla::detail::MutexImpl::unlock()
 {
-  ReleaseSRWLockExclusive(&platformData()->lock);
+  LeaveCriticalSection(&platformData()->criticalSection);
 }
 
 mozilla::detail::MutexImpl::PlatformData*
 mozilla::detail::MutexImpl::platformData()
 {
   static_assert(sizeof(platformData_) >= sizeof(PlatformData),
                 "platformData_ is too small");
   return reinterpret_cast<PlatformData*>(platformData_);