Bug 1317259 - Prevent double init in mozilla::TimeStamp::Startup() on Windows. r?froydnj draft
authorCervantes Yu <cyu@mozilla.com>
Mon, 14 Nov 2016 19:01:17 +0800
changeset 438395 ae3f0baf416325f0ab43e324340fd6a920ba862d
parent 438112 47e0584afe0ab0b867412189c610b302b6ba0ea7
child 536891 8f9ab402c388273fbd02694e9459f30d8cd9bf09
push id35691
push usercyu@mozilla.com
push dateMon, 14 Nov 2016 11:03:00 +0000
reviewersfroydnj
bugs1317259
milestone52.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.