b=560717; fix TimeStamp initialization in TimeStamp_posix; r=bsmedberg
authorVladimir Vukicevic <vladimir@pobox.com>
Mon, 26 Apr 2010 14:26:40 -0700
changeset 41357 1e04db0f5a3000cc2125fd09cd07a92fa9a6948c
parent 41356 f6298f002f1c28b8e1cae9515811b276e50744e8
child 41358 861f07be1937071488b7fe0d3f4f600b5eb1310d
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs560717
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
b=560717; fix TimeStamp initialization in TimeStamp_posix; r=bsmedberg
xpcom/ds/TimeStamp_posix.cpp
--- a/xpcom/ds/TimeStamp_posix.cpp
+++ b/xpcom/ds/TimeStamp_posix.cpp
@@ -158,33 +158,49 @@ TimeDuration::FromMilliseconds(PRInt32 a
 }
 
 TimeDuration
 TimeDuration::Resolution()
 {
   return TimeDuration::FromTicks(sResolution);
 }
 
+struct TimeStampInitialization
+{
+  TimeStampInitialization() {
+    TimeStamp::Startup();
+  }
+  ~TimeStampInitialization() {
+    TimeStamp::Shutdown();
+  }
+};
+
+static TimeStampInitialization initOnce;
+static PRBool gInitialized = PR_FALSE;
 
 nsresult
 TimeStamp::Startup()
 {
+  if (gInitialized)
+    return NS_OK;
+
   struct timespec dummy;
   if (0 != clock_gettime(CLOCK_MONOTONIC, &dummy))
       NS_RUNTIMEABORT("CLOCK_MONOTONIC is absent!");
 
   sResolution = ClockResolutionNs();
 
   // find the number of significant digits in sResolution, for the
   // sake of ToSecondsSigDigits()
   for (sResolutionSigDigs = 1;
        !(sResolutionSigDigs == sResolution
          || 10*sResolutionSigDigs > sResolution);
        sResolutionSigDigs *= 10);
 
+  gInitialized = PR_TRUE;
   return NS_OK;
 }
 
 void
 TimeStamp::Shutdown()
 {
 }