nsprpub/pr/src/md/os2/os2inrval.c

Wed, 31 Dec 2014 07:53:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:53:36 +0100
branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
permissions
-rw-r--r--

Correct small whitespace inconsistency, lost while renaming variables.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 * OS/2 interval timers
michael@0 8 *
michael@0 9 */
michael@0 10
michael@0 11 #include "primpl.h"
michael@0 12
michael@0 13 static PRBool useHighResTimer = PR_FALSE;
michael@0 14 PRIntervalTime _os2_ticksPerSec = -1;
michael@0 15 PRIntn _os2_bitShift = 0;
michael@0 16 PRInt32 _os2_highMask = 0;
michael@0 17
michael@0 18 void
michael@0 19 _PR_MD_INTERVAL_INIT()
michael@0 20 {
michael@0 21 char *envp;
michael@0 22 ULONG timerFreq;
michael@0 23 APIRET rc;
michael@0 24
michael@0 25 if ((envp = getenv("NSPR_OS2_NO_HIRES_TIMER")) != NULL) {
michael@0 26 if (atoi(envp) == 1)
michael@0 27 return;
michael@0 28 }
michael@0 29
michael@0 30 timerFreq = 0; /* OS/2 high-resolution timer frequency in Hz */
michael@0 31 rc = DosTmrQueryFreq(&timerFreq);
michael@0 32 if (NO_ERROR == rc) {
michael@0 33 useHighResTimer = PR_TRUE;
michael@0 34 PR_ASSERT(timerFreq != 0);
michael@0 35 while (timerFreq > PR_INTERVAL_MAX) {
michael@0 36 timerFreq >>= 1;
michael@0 37 _os2_bitShift++;
michael@0 38 _os2_highMask = (_os2_highMask << 1)+1;
michael@0 39 }
michael@0 40
michael@0 41 _os2_ticksPerSec = timerFreq;
michael@0 42 PR_ASSERT(_os2_ticksPerSec > PR_INTERVAL_MIN);
michael@0 43 }
michael@0 44 }
michael@0 45
michael@0 46 PRIntervalTime
michael@0 47 _PR_MD_GET_INTERVAL()
michael@0 48 {
michael@0 49 if (useHighResTimer) {
michael@0 50 QWORD timestamp;
michael@0 51 PRInt32 top;
michael@0 52 APIRET rc = DosTmrQueryTime(&timestamp);
michael@0 53 if (NO_ERROR != rc) {
michael@0 54 return -1;
michael@0 55 }
michael@0 56 /* Sadly, nspr requires the interval to range from 1000 ticks per
michael@0 57 * second to only 100000 ticks per second. DosTmrQueryTime is too
michael@0 58 * high resolution...
michael@0 59 */
michael@0 60 top = timestamp.ulHi & _os2_highMask;
michael@0 61 top = top << (32 - _os2_bitShift);
michael@0 62 timestamp.ulLo = timestamp.ulLo >> _os2_bitShift;
michael@0 63 timestamp.ulLo = timestamp.ulLo + top;
michael@0 64 return (PRUint32)timestamp.ulLo;
michael@0 65 } else {
michael@0 66 ULONG msCount = -1;
michael@0 67 DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &msCount, sizeof(msCount));
michael@0 68 return msCount;
michael@0 69 }
michael@0 70 }
michael@0 71
michael@0 72 PRIntervalTime
michael@0 73 _PR_MD_INTERVAL_PER_SEC()
michael@0 74 {
michael@0 75 if (useHighResTimer) {
michael@0 76 return _os2_ticksPerSec;
michael@0 77 } else {
michael@0 78 return 1000;
michael@0 79 }
michael@0 80 }

mercurial