Bugzilla Bug 307527: implement NSPR interval timer with timeGetTime instead MOZILLA_1_8_BRANCH
authorwtchang%redhat.com
Tue, 07 Feb 2006 02:17:24 +0000
branchMOZILLA_1_8_BRANCH
changeset 3564 107861333531cb0b1c8f76e0cc619ec5f9b98c66
parent 3555 a0840f24a3d19db2c90f9607106a46e45f58035c
child 3566 3fb23d4b1c2196fd4a20561761ee3ffcf49a7051
push idunknown
push userunknown
push dateunknown
bugs307527
Bugzilla Bug 307527: implement NSPR interval timer with timeGetTime instead of QueryPerformanceCounter or GetTickCount. r=darin,bienvenu. Modified files: pr/src/Makefile.in ntinrval.c Tag: MOZILLA_1_8_BRANCH
pr/src/Makefile.in
pr/src/md/windows/ntinrval.c
--- a/pr/src/Makefile.in
+++ b/pr/src/Makefile.in
@@ -193,19 +193,19 @@ OS_LIBS		= -lsocket -lc
 endif
 
 ifeq ($(OS_ARCH),NEWS-OS)
 OS_LIBS		= -lsocket -lnsl -lgen -lresolv
 endif
 
 ifeq ($(OS_ARCH),WINNT)
 ifdef NS_USE_GCC
-OS_LIBS		= -ladvapi32 -lwsock32
+OS_LIBS		= -ladvapi32 -lwsock32 -lwinmm
 else
-OS_LIBS		= advapi32.lib wsock32.lib
+OS_LIBS		= advapi32.lib wsock32.lib winmm.lib
 endif
 endif
 
 ifeq ($(OS_TARGET),MacOSX)
 OS_LIBS		= -framework CoreServices -framework CoreFoundation
 endif
 
 ifdef GC_LEAK_DETECTOR
--- a/pr/src/md/windows/ntinrval.c
+++ b/pr/src/md/windows/ntinrval.c
@@ -37,88 +37,30 @@
 
 /*
  * NT interval timers
  *
  */
 
 #include "primpl.h"
 
-#if defined(WIN16)
-#include <win/compobj.h>
-#define QueryPerformanceFrequency(x)   FALSE
-#define QueryPerformanceCounter(x)     FALSE
-#endif
-
-static PRIntn _nt_bitShift = 0;
-static PRInt32 _nt_ticksPerSec = -1;
-
 void
 _PR_MD_INTERVAL_INIT()
 {
-    LARGE_INTEGER count;
-
-    if (QueryPerformanceFrequency(&count)) {
-        /*
-         * HighPart is signed (LONG).  Assert that its sign bit is 0
-         * because we will be right shifting it.  LowPart is unsigned
-         * (DWORD).
-         */
-        PR_ASSERT(count.HighPart >= 0);
-        while(count.HighPart) {
-            count.LowPart = (count.HighPart << 31) + (count.LowPart >> 1);
-            count.HighPart >>= 1;
-            _nt_bitShift++;
-        }
-        while(count.LowPart > PR_INTERVAL_MAX) {
-            count.LowPart >>= 1;
-            _nt_bitShift++;
-        }
-
-        /*
-         * We can't use the performance counter if after
-         * normalization we are left with fewer than 32 bits.
-         */
-        if (_nt_bitShift <= 32) {
-            _nt_ticksPerSec = count.LowPart;
-            PR_ASSERT(_nt_ticksPerSec > PR_INTERVAL_MIN);
-            return;
-        }
-    }
-    _nt_ticksPerSec = -1;
 }
 
 PRIntervalTime 
 _PR_MD_GET_INTERVAL()
 {
-    LARGE_INTEGER count;
-
-   /* Sadly; nspr requires the interval to range from 1000 ticks per second
-    * to only 100000 ticks per second; QueryPerformanceCounter is too high
-    * resolution...
-    */
-    if (_nt_ticksPerSec != -1) {
-        (void)QueryPerformanceCounter(&count);
-        PR_ASSERT(_nt_bitShift <= 32);
-        if (_nt_bitShift == 32) {
-            return (PRUint32)count.HighPart;
-        } else {
-            return (PRUint32)((count.HighPart << (32 - _nt_bitShift))
-                    + (count.LowPart >> _nt_bitShift));
-        }
-    } else
 #if defined(__MINGW32__)
-        return time();
+    return time();
 #elif defined(WIN16)
-        return clock();        /* milliseconds since application start */
+    return clock();        /* milliseconds since application start */
 #else
-        return GetTickCount();  /* milliseconds since system start */
+    return timeGetTime();  /* milliseconds since system start */
 #endif
 }
 
 PRIntervalTime 
 _PR_MD_INTERVAL_PER_SEC()
 {
-    if (_nt_ticksPerSec != -1)
-        return _nt_ticksPerSec;
-    else
-        return 1000;
+    return 1000;
 }