home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / src / md / windows / ntinrval.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.4 KB  |  87 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /*
  20.  * NT interval timers
  21.  *
  22.  */
  23.  
  24. #include "primpl.h"
  25.  
  26. #if defined(WIN16)
  27. #include <win/compobj.h>
  28. #define QueryPerformanceFrequency(x)   FALSE
  29. #define QueryPerformanceCounter(x)     FALSE
  30. #endif
  31.  
  32. PRIntn _nt_bitShift = 0;
  33. PRInt32 _nt_highMask = 0;
  34. PRInt32 _nt_ticksPerSec = -1;
  35.  
  36. void
  37. _PR_MD_INTERVAL_INIT()
  38. {
  39.     LARGE_INTEGER count;
  40.  
  41.     if (QueryPerformanceFrequency(&count)) {
  42.         while(count.LowPart > PR_INTERVAL_MAX) {
  43.             count.LowPart >>= 1;
  44.             _nt_bitShift++;
  45.             _nt_highMask = (_nt_highMask << 1)+1;
  46.         }
  47.  
  48.         _nt_ticksPerSec = count.LowPart;
  49.         PR_ASSERT(_nt_ticksPerSec > PR_INTERVAL_MIN);
  50.     } else 
  51.         _nt_ticksPerSec = -1;
  52. }
  53.  
  54. PRIntervalTime 
  55. _PR_MD_GET_INTERVAL()
  56. {
  57.     LARGE_INTEGER count;
  58.  
  59.    /* Sadly; nspr requires the interval to range from 1000 ticks per second
  60.     * to only 100000 ticks per second; QueryPerformanceCounter is too high
  61.     * resolution...
  62.     */
  63.     if (QueryPerformanceCounter(&count)) {
  64.         PRInt32 top = count.HighPart & _nt_highMask;
  65.         top = top << (32 - _nt_bitShift);
  66.         count.LowPart = count.LowPart >> _nt_bitShift;   
  67.         count.LowPart = count.LowPart + top; 
  68.         return (PRUint32)count.LowPart;
  69.     } else
  70. #if defined(WIN16)
  71.         return clock();        /* milliseconds since application start */
  72. #else
  73.         return timeGetTime();  /* milliseconds since system start */
  74. #endif
  75. }
  76.  
  77. PRIntervalTime 
  78. _PR_MD_INTERVAL_PER_SEC()
  79. {
  80.     LARGE_INTEGER count;
  81.  
  82.     if (_nt_ticksPerSec != -1)
  83.         return _nt_ticksPerSec;
  84.     else
  85.         return 1000;
  86. }
  87.