Bug 1317259 - Prevent double init in mozilla::TimeStamp::Startup() on Windows. r=froydnj
authorCervantes Yu <cyu@mozilla.com>
Mon, 14 Nov 2016 19:01:17 +0800
changeset 439634 392c92c5a3742165c9275b82f5affcde05b08d69
parent 439633 ae6bb745b299211d698513214332a8d67cc13b6f
child 439635 21589b5736232ee817589aeb3cc1bcc08720e766
push id36064
push userrthijssen@mozilla.com
push dateWed, 16 Nov 2016 13:38:27 +0000
reviewersfroydnj
bugs1317259
milestone53.0a1
Bug 1317259 - Prevent double init in mozilla::TimeStamp::Startup() on Windows. r=froydnj MozReview-Commit-ID: JKfEFqo5qHj
mozglue/misc/TimeStamp_windows.cpp
--- a/mozglue/misc/TimeStamp_windows.cpp
+++ b/mozglue/misc/TimeStamp_windows.cpp
@@ -469,19 +469,27 @@ HasStableTSC()
   }
 
   __cpuid(regs, 0x80000007);
   // if bit 8 is set than TSC will run at a constant rate
   // in all ACPI P-state, C-states and T-states
   return regs[3] & (1 << 8);
 }
 
+static bool gInitialized = false;
+
 MFBT_API void
 TimeStamp::Startup()
 {
+  if (gInitialized) {
+    return;
+  }
+
+  gInitialized = true;
+
   // Decide which implementation to use for the high-performance timer.
 
   HMODULE kernelDLL = GetModuleHandleW(L"kernel32.dll");
   sGetTickCount64 = reinterpret_cast<GetTickCount64_t>(
     GetProcAddress(kernelDLL, "GetTickCount64"));
   if (!sGetTickCount64) {
     // If the platform does not support the GetTickCount64 (Windows XP doesn't),
     // then use our fallback implementation based on GetTickCount.