home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / src / md / os2 / os2inrval.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.2 KB  |  82 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.  * OS/2 interval timers
  21.  *
  22.  */
  23.  
  24. #include "primpl.h"
  25.  
  26. ULONG _os2_ticksPerSec = -1;
  27. PRIntn _os2_bitShift = 0;
  28. PRInt32 _os2_highMask = 0;
  29.  
  30.  
  31.    
  32. PR_IMPLEMENT(void)
  33. _PR_MD_INTERVAL_INIT()
  34. {
  35.    ULONG count;
  36.  
  37.    if (DosTmrQueryFreq(&_os2_ticksPerSec) == NO_ERROR)
  38.    {
  39.       while(_os2_ticksPerSec > PR_INTERVAL_MAX) {
  40.           _os2_ticksPerSec >>= 1;
  41.           _os2_bitShift++;
  42.           _os2_highMask = (_os2_highMask << 1)+1;
  43.       }
  44.    }
  45.    else
  46.       _os2_ticksPerSec = -1;
  47.  
  48.    PR_ASSERT(_os2_ticksPerSec > PR_INTERVAL_MIN && _os2_ticksPerSec < PR_INTERVAL_MAX);
  49. }
  50.  
  51. PR_IMPLEMENT(PRIntervalTime) 
  52. _PR_MD_GET_INTERVAL()
  53. {
  54.    QWORD count;
  55.  
  56.    /* Sadly; nspr requires the interval to range from 1000 ticks per second
  57.     * to only 100000 ticks per second; Counter is too high
  58.     * resolution...
  59.     */
  60.     if (DosTmrQueryTime(&count) == NO_ERROR) {
  61.         PRInt32 top = count.ulHi & _os2_highMask;
  62.         top = top << (32 - _os2_bitShift);
  63.         count.ulLo = count.ulLo >> _os2_bitShift;   
  64.         count.ulHi = count.ulLo + top; 
  65.         return (PRUint32)count.ulLo;
  66.     }
  67.     else{
  68.        ULONG msCount = PR_FAILURE;
  69.        DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &msCount, sizeof(msCount));
  70.        return msCount;
  71.     }
  72. }
  73.  
  74. PR_IMPLEMENT(PRIntervalTime) 
  75. _PR_MD_INTERVAL_PER_SEC()
  76. {
  77.     if(_os2_ticksPerSec != -1)
  78.        return _os2_ticksPerSec;
  79.     else
  80.        return 1000;
  81. }
  82.