Bug 461841: Unshuffle system-specific definitions of PRMJ_Now. r=crowder
authorJim Blandy <jimb@mozilla.org>
Fri, 16 Jan 2009 14:10:47 -0800
changeset 23833 d220fbb8ea6a58e7c304b29895c77d3a419ba20b
parent 23832 fb428e8612428c29c4d4e0d55d3b5af6f58c1e3c
child 23834 7cf6db4b75c0daca9a188d839ca06dacbefbed49
push id4750
push userdougt@mozilla.com
push dateFri, 16 Jan 2009 22:19:49 +0000
treeherdermozilla-central@7cf6db4b75c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscrowder
bugs461841
milestone1.9.2a1pre
Bug 461841: Unshuffle system-specific definitions of PRMJ_Now. r=crowder Every piece of the body of js/src/prmjtime.cpp's PRMJ_Now function was in a preprocessor conditional --- it was three entirely independent implementations shuffled together. Unshuffling them prepares the way for adding a new WinCE definition.
js/src/prmjtime.cpp
--- a/js/src/prmjtime.cpp
+++ b/js/src/prmjtime.cpp
@@ -260,16 +260,56 @@ static PRCallOnceType calibrationOnce = 
 #define MUTEX_UNLOCK(m)
 #define MUTEX_SETSPINCOUNT(m, c)
 
 #endif
 
 
 #endif /* XP_WIN */
 
+
+#if defined(XP_OS2)
+JSInt64
+PRMJ_Now(void)
+{
+    JSInt64 s, us, ms2us, s2us;
+    struct timeb b;
+
+    ftime(&b);
+    JSLL_UI2L(ms2us, PRMJ_USEC_PER_MSEC);
+    JSLL_UI2L(s2us, PRMJ_USEC_PER_SEC);
+    JSLL_UI2L(s, b.time);
+    JSLL_UI2L(us, b.millitm);
+    JSLL_MUL(us, us, ms2us);
+    JSLL_MUL(s, s, s2us);
+    JSLL_ADD(s, s, us);
+    return s;
+}
+
+#elif defined(XP_UNIX) || defined(XP_BEOS)
+JSInt64
+PRMJ_Now(void)
+{
+    struct timeval tv;
+    JSInt64 s, us, s2us;
+
+#ifdef _SVID_GETTOD   /* Defined only on Solaris, see Solaris <sys/types.h> */
+    gettimeofday(&tv);
+#else
+    gettimeofday(&tv, 0);
+#endif /* _SVID_GETTOD */
+    JSLL_UI2L(s2us, PRMJ_USEC_PER_SEC);
+    JSLL_UI2L(s, tv.tv_sec);
+    JSLL_UI2L(us, tv.tv_usec);
+    JSLL_MUL(s, s, s2us);
+    JSLL_ADD(s, s, us);
+    return s;
+}
+
+#elif defined(XP_WIN)
 /*
 
 Win32 python-esque pseudo code
 Please see bug 363258 for why the win32 timing code is so complex.
 
 calibration mutex : Win32CriticalSection(spincount=0)
 data mutex : Win32CriticalSection(spincount=4096)
 
@@ -326,47 +366,24 @@ def PRMJ_Now():
       returnedTime = lowres
   while needCalibration
 
 */
 
 JSInt64
 PRMJ_Now(void)
 {
-#ifdef XP_OS2
-    JSInt64 s, us, ms2us, s2us;
-    struct timeb b;
-#endif
-#ifdef XP_WIN
     static int nCalls = 0;
     long double lowresTime, highresTimerValue;
     FILETIME ft;
     LARGE_INTEGER now;
     JSBool calibrated = JS_FALSE;
     JSBool needsCalibration = JS_FALSE;
     JSInt64 returnedTime;
     long double cachedOffset = 0.0;
-#endif
-#if defined(XP_UNIX) || defined(XP_BEOS)
-    struct timeval tv;
-    JSInt64 s, us, s2us;
-#endif /* XP_UNIX */
-
-#ifdef XP_OS2
-    ftime(&b);
-    JSLL_UI2L(ms2us, PRMJ_USEC_PER_MSEC);
-    JSLL_UI2L(s2us, PRMJ_USEC_PER_SEC);
-    JSLL_UI2L(s, b.time);
-    JSLL_UI2L(us, b.millitm);
-    JSLL_MUL(us, us, ms2us);
-    JSLL_MUL(s, s, s2us);
-    JSLL_ADD(s, s, us);
-    return s;
-#endif
-#ifdef XP_WIN
 
     /* To avoid regressing startup time (where high resolution is likely
        not needed), give the old behavior for the first few calls.
        This does not appear to be needed on Vista as the timeBegin/timeEndPeriod
        calls seem to immediately take effect. */
     int thiscall = JS_ATOMIC_INCREMENT(&nCalls);
     /* 10 seems to be the number of calls to load with a blank homepage */
     if (thiscall <= 10) {
@@ -483,32 +500,20 @@ PRMJ_Now(void)
             }
         } else {
             /* No high resolution timer is available, so fall back */
             returnedTime = (JSInt64)lowresTime;
         }
     } while (needsCalibration);
 
     return returnedTime;
-#endif
-
-#if defined(XP_UNIX) || defined(XP_BEOS)
-#ifdef _SVID_GETTOD   /* Defined only on Solaris, see Solaris <sys/types.h> */
-    gettimeofday(&tv);
+}
 #else
-    gettimeofday(&tv, 0);
-#endif /* _SVID_GETTOD */
-    JSLL_UI2L(s2us, PRMJ_USEC_PER_SEC);
-    JSLL_UI2L(s, tv.tv_sec);
-    JSLL_UI2L(us, tv.tv_usec);
-    JSLL_MUL(s, s, s2us);
-    JSLL_ADD(s, s, us);
-    return s;
-#endif /* XP_UNIX */
-}
+#error "No implementation of PRMJ_Now was selected."
+#endif
 
 /* Get the DST timezone offset for the time passed in */
 JSInt64
 PRMJ_DSTOffset(JSInt64 local_time)
 {
     JSInt64 us2s;
     time_t local;
     JSInt32 diff;