summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtchang%redhat.com <devnull@localhost>2006-02-07 03:32:12 +0000
committerwtchang%redhat.com <devnull@localhost>2006-02-07 03:32:12 +0000
commit808d5fdcacd04f00a77cc84816418a5c933f3b50 (patch)
tree83cdc8e66646f30b4677e459120defa7ff4c6b73
parent8dfbb00bb2ec758549ed8843b7a851f4188020ed (diff)
downloadnspr-hg-808d5fdcacd04f00a77cc84816418a5c933f3b50.tar.gz
Bugzilla Bug 307527: backed out the previous checkin because Mozilla
tinderboxes did not rerun configure to regenerate pr/src/Makefile. Modified files: pr/src/Makefile.in ntinrval.c Tag: NSPRPUB_PRE_4_2_CLIENT_BRANCH
-rw-r--r--pr/src/Makefile.in4
-rw-r--r--pr/src/md/windows/ntinrval.c66
2 files changed, 64 insertions, 6 deletions
diff --git a/pr/src/Makefile.in b/pr/src/Makefile.in
index edaaa15f..4a3ac42a 100644
--- a/pr/src/Makefile.in
+++ b/pr/src/Makefile.in
@@ -198,9 +198,9 @@ endif
ifeq ($(OS_ARCH),WINNT)
ifdef NS_USE_GCC
-OS_LIBS = -ladvapi32 -lwsock32 -lwinmm
+OS_LIBS = -ladvapi32 -lwsock32
else
-OS_LIBS = advapi32.lib wsock32.lib winmm.lib
+OS_LIBS = advapi32.lib wsock32.lib
endif
endif
diff --git a/pr/src/md/windows/ntinrval.c b/pr/src/md/windows/ntinrval.c
index d19735e7..494f6e83 100644
--- a/pr/src/md/windows/ntinrval.c
+++ b/pr/src/md/windows/ntinrval.c
@@ -42,25 +42,83 @@
#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 timeGetTime(); /* milliseconds since system start */
+ return GetTickCount(); /* milliseconds since system start */
#endif
}
PRIntervalTime
_PR_MD_INTERVAL_PER_SEC()
{
- return 1000;
+ if (_nt_ticksPerSec != -1)
+ return _nt_ticksPerSec;
+ else
+ return 1000;
}