nsprpub/pr/src/misc/prinrval.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 * file: prinrval.c
michael@0 8 * description: implementation for the kernel interval timing functions
michael@0 9 */
michael@0 10
michael@0 11 #include "primpl.h"
michael@0 12
michael@0 13 /*
michael@0 14 *-----------------------------------------------------------------------
michael@0 15 *
michael@0 16 * _PR_InitClock --
michael@0 17 *
michael@0 18 *
michael@0 19 *-----------------------------------------------------------------------
michael@0 20 */
michael@0 21
michael@0 22 void _PR_InitClock(void)
michael@0 23 {
michael@0 24 _PR_MD_INTERVAL_INIT();
michael@0 25 #ifdef DEBUG
michael@0 26 {
michael@0 27 PRIntervalTime ticksPerSec = PR_TicksPerSecond();
michael@0 28
michael@0 29 PR_ASSERT(ticksPerSec >= PR_INTERVAL_MIN);
michael@0 30 PR_ASSERT(ticksPerSec <= PR_INTERVAL_MAX);
michael@0 31 }
michael@0 32 #endif /* DEBUG */
michael@0 33 }
michael@0 34
michael@0 35 PR_IMPLEMENT(PRIntervalTime) PR_IntervalNow(void)
michael@0 36 {
michael@0 37 if (!_pr_initialized) _PR_ImplicitInitialization();
michael@0 38 return _PR_MD_GET_INTERVAL();
michael@0 39 } /* PR_IntervalNow */
michael@0 40
michael@0 41 PR_EXTERN(PRUint32) PR_TicksPerSecond(void)
michael@0 42 {
michael@0 43 if (!_pr_initialized) _PR_ImplicitInitialization();
michael@0 44 return _PR_MD_INTERVAL_PER_SEC();
michael@0 45 } /* PR_TicksPerSecond */
michael@0 46
michael@0 47 PR_IMPLEMENT(PRIntervalTime) PR_SecondsToInterval(PRUint32 seconds)
michael@0 48 {
michael@0 49 return seconds * PR_TicksPerSecond();
michael@0 50 } /* PR_SecondsToInterval */
michael@0 51
michael@0 52 PR_IMPLEMENT(PRIntervalTime) PR_MillisecondsToInterval(PRUint32 milli)
michael@0 53 {
michael@0 54 PRIntervalTime ticks;
michael@0 55 PRUint64 tock, tps, msecPerSec, rounding;
michael@0 56 LL_UI2L(tock, milli);
michael@0 57 LL_I2L(msecPerSec, PR_MSEC_PER_SEC);
michael@0 58 LL_I2L(rounding, (PR_MSEC_PER_SEC >> 1));
michael@0 59 LL_I2L(tps, PR_TicksPerSecond());
michael@0 60 LL_MUL(tock, tock, tps);
michael@0 61 LL_ADD(tock, tock, rounding);
michael@0 62 LL_DIV(tock, tock, msecPerSec);
michael@0 63 LL_L2UI(ticks, tock);
michael@0 64 return ticks;
michael@0 65 } /* PR_MillisecondsToInterval */
michael@0 66
michael@0 67 PR_IMPLEMENT(PRIntervalTime) PR_MicrosecondsToInterval(PRUint32 micro)
michael@0 68 {
michael@0 69 PRIntervalTime ticks;
michael@0 70 PRUint64 tock, tps, usecPerSec, rounding;
michael@0 71 LL_UI2L(tock, micro);
michael@0 72 LL_I2L(usecPerSec, PR_USEC_PER_SEC);
michael@0 73 LL_I2L(rounding, (PR_USEC_PER_SEC >> 1));
michael@0 74 LL_I2L(tps, PR_TicksPerSecond());
michael@0 75 LL_MUL(tock, tock, tps);
michael@0 76 LL_ADD(tock, tock, rounding);
michael@0 77 LL_DIV(tock, tock, usecPerSec);
michael@0 78 LL_L2UI(ticks, tock);
michael@0 79 return ticks;
michael@0 80 } /* PR_MicrosecondsToInterval */
michael@0 81
michael@0 82 PR_IMPLEMENT(PRUint32) PR_IntervalToSeconds(PRIntervalTime ticks)
michael@0 83 {
michael@0 84 return ticks / PR_TicksPerSecond();
michael@0 85 } /* PR_IntervalToSeconds */
michael@0 86
michael@0 87 PR_IMPLEMENT(PRUint32) PR_IntervalToMilliseconds(PRIntervalTime ticks)
michael@0 88 {
michael@0 89 PRUint32 milli;
michael@0 90 PRUint64 tock, tps, msecPerSec, rounding;
michael@0 91 LL_UI2L(tock, ticks);
michael@0 92 LL_I2L(msecPerSec, PR_MSEC_PER_SEC);
michael@0 93 LL_I2L(tps, PR_TicksPerSecond());
michael@0 94 LL_USHR(rounding, tps, 1);
michael@0 95 LL_MUL(tock, tock, msecPerSec);
michael@0 96 LL_ADD(tock, tock, rounding);
michael@0 97 LL_DIV(tock, tock, tps);
michael@0 98 LL_L2UI(milli, tock);
michael@0 99 return milli;
michael@0 100 } /* PR_IntervalToMilliseconds */
michael@0 101
michael@0 102 PR_IMPLEMENT(PRUint32) PR_IntervalToMicroseconds(PRIntervalTime ticks)
michael@0 103 {
michael@0 104 PRUint32 micro;
michael@0 105 PRUint64 tock, tps, usecPerSec, rounding;
michael@0 106 LL_UI2L(tock, ticks);
michael@0 107 LL_I2L(usecPerSec, PR_USEC_PER_SEC);
michael@0 108 LL_I2L(tps, PR_TicksPerSecond());
michael@0 109 LL_USHR(rounding, tps, 1);
michael@0 110 LL_MUL(tock, tock, usecPerSec);
michael@0 111 LL_ADD(tock, tock, rounding);
michael@0 112 LL_DIV(tock, tock, tps);
michael@0 113 LL_L2UI(micro, tock);
michael@0 114 return micro;
michael@0 115 } /* PR_IntervalToMicroseconds */
michael@0 116
michael@0 117 /* prinrval.c */
michael@0 118

mercurial