Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(509)

Unified Diff: nspr/pr/src/md/windows/w95cv.c

Issue 68173008: Update to NSPR 4.10.2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/nss/
Patch Set: Update README.chromium Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « nspr/pr/src/md/windows/ntsem.c ('k') | nspr/pr/src/md/windows/w95io.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: nspr/pr/src/md/windows/w95cv.c
===================================================================
--- nspr/pr/src/md/windows/w95cv.c (revision 233722)
+++ nspr/pr/src/md/windows/w95cv.c (working copy)
@@ -304,6 +304,59 @@
return;
}
+typedef BOOL (WINAPI *INITIALIZECRITICALSECTIONEX)(
+ CRITICAL_SECTION *lpCriticalSection,
+ DWORD dwSpinCount,
+ DWORD Flags);
+
+static INITIALIZECRITICALSECTIONEX sInitializeCriticalSectionEx;
+
+void _PR_MD_INIT_LOCKS(void)
+{
+ /*
+ * Starting with Windows Vista, every CRITICAL_SECTION allocates an extra
+ * RTL_CRITICAL_SECTION_DEBUG object. Unfortunately, this debug object is
+ * not reclaimed by DeleteCriticalSection(), causing an apparent memory
+ * leak. This is a debugging "feature", not a bug. If we are running on
+ * Vista or later, use InitializeCriticalSectionEx() to allocate
+ * CRITICAL_SECTIONs without debug objects.
+ */
+ HMODULE hKernel32 = GetModuleHandle("kernel32.dll");
+ PR_ASSERT(hKernel32);
+ PR_ASSERT(!sInitializeCriticalSectionEx);
+ sInitializeCriticalSectionEx = (INITIALIZECRITICALSECTIONEX)
+ GetProcAddress(hKernel32, "InitializeCriticalSectionEx");
+}
+
+/*
+ * By default, CRITICAL_SECTIONs are initialized with a spin count of 0.
+ * Joe Duffy's "Concurrent Programming on Windows" book suggests 1500 is
+ * a "reasonable starting point". On single-processor systems, the spin
+ * count is ignored and the critical section spin count is set to 0.
+ */
+#define LOCK_SPIN_COUNT 1500
+
+PRStatus _PR_MD_NEW_LOCK(_MDLock *lock)
+{
+ CRITICAL_SECTION *cs = &lock->mutex;
+ BOOL ok;
+
+ if (sInitializeCriticalSectionEx) {
+ ok = sInitializeCriticalSectionEx(cs, LOCK_SPIN_COUNT,
+ CRITICAL_SECTION_NO_DEBUG_INFO);
+ } else {
+ ok = InitializeCriticalSectionAndSpinCount(cs, LOCK_SPIN_COUNT);
+ }
+ if (!ok) {
+ _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
+ return PR_FAILURE;
+ }
+
+ lock->notified.length = 0;
+ lock->notified.link = NULL;
+ return PR_SUCCESS;
+}
+
void _PR_MD_UNLOCK(_MDLock *lock)
{
if (0 != lock->notified.length) {
@@ -311,5 +364,4 @@
} else {
LeaveCriticalSection(&lock->mutex);
}
- return;
}
« no previous file with comments | « nspr/pr/src/md/windows/ntsem.c ('k') | nspr/pr/src/md/windows/w95io.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698