Bug 1358251: EnsureSymInitialized doesn't need to EnsureWalkThreadReady. r=mstange
authorDavid Major <dmajor@mozilla.com>
Mon, 01 May 2017 15:34:50 -0400
changeset 404044 5dc6f1a89b79d16b942517bbb0d09ebac0f07158
parent 404043 492530a9b80ac49ebd53a00a874e29951b48c619
child 404045 f4ad40ab582e74e1ae811a4f974370227fef7e69
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1358251
milestone55.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 1358251: EnsureSymInitialized doesn't need to EnsureWalkThreadReady. r=mstange
mozglue/misc/StackWalk.cpp
--- a/mozglue/misc/StackWalk.cpp
+++ b/mozglue/misc/StackWalk.cpp
@@ -243,16 +243,27 @@ PrintError(const char* aPrefix)
     nullptr
   );
   fprintf(stderr, "### ERROR: %s: %s",
           aPrefix, lpMsgBuf ? lpMsgBuf : "(null)\n");
   fflush(stderr);
   LocalFree(lpMsgBuf);
 }
 
+static void
+InitializeDbgHelpCriticalSection()
+{
+  static bool initialized = false;
+  if (initialized) {
+    return;
+  }
+  ::InitializeCriticalSection(&gDbgHelpCS);
+  initialized = true;
+}
+
 static unsigned int WINAPI WalkStackThread(void* aData);
 
 static bool
 EnsureWalkThreadReady()
 {
   static bool walkThreadReady = false;
   static HANDLE stackWalkThread = nullptr;
   static HANDLE readyEvent = nullptr;
@@ -295,18 +306,17 @@ EnsureWalkThreadReady()
     // have signalled the event. If that is the case, give up for now and
     // try again next time we're called.
     return false;
   }
   ::CloseHandle(readyEvent);
   stackWalkThread = nullptr;
   readyEvent = nullptr;
 
-
-  ::InitializeCriticalSection(&gDbgHelpCS);
+  InitializeDbgHelpCriticalSection();
 
   return walkThreadReady = true;
 }
 
 static void
 WalkStackMain64(struct WalkStackData* aData)
 {
   // Get a context for the specified thread.
@@ -846,19 +856,17 @@ EnsureSymInitialized()
 {
   static bool gInitialized = false;
   bool retStat;
 
   if (gInitialized) {
     return gInitialized;
   }
 
-  if (!EnsureWalkThreadReady()) {
-    return false;
-  }
+  InitializeDbgHelpCriticalSection();
 
   SymSetOptions(SYMOPT_LOAD_LINES | SYMOPT_UNDNAME);
   retStat = SymInitialize(GetCurrentProcess(), nullptr, TRUE);
   if (!retStat) {
     PrintError("SymInitialize");
   }
 
   gInitialized = retStat;