michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * file: prinrval.c michael@0: * description: implementation for the kernel interval timing functions michael@0: */ michael@0: michael@0: #include "primpl.h" michael@0: michael@0: /* michael@0: *----------------------------------------------------------------------- michael@0: * michael@0: * _PR_InitClock -- michael@0: * michael@0: * michael@0: *----------------------------------------------------------------------- michael@0: */ michael@0: michael@0: void _PR_InitClock(void) michael@0: { michael@0: _PR_MD_INTERVAL_INIT(); michael@0: #ifdef DEBUG michael@0: { michael@0: PRIntervalTime ticksPerSec = PR_TicksPerSecond(); michael@0: michael@0: PR_ASSERT(ticksPerSec >= PR_INTERVAL_MIN); michael@0: PR_ASSERT(ticksPerSec <= PR_INTERVAL_MAX); michael@0: } michael@0: #endif /* DEBUG */ michael@0: } michael@0: michael@0: PR_IMPLEMENT(PRIntervalTime) PR_IntervalNow(void) michael@0: { michael@0: if (!_pr_initialized) _PR_ImplicitInitialization(); michael@0: return _PR_MD_GET_INTERVAL(); michael@0: } /* PR_IntervalNow */ michael@0: michael@0: PR_EXTERN(PRUint32) PR_TicksPerSecond(void) michael@0: { michael@0: if (!_pr_initialized) _PR_ImplicitInitialization(); michael@0: return _PR_MD_INTERVAL_PER_SEC(); michael@0: } /* PR_TicksPerSecond */ michael@0: michael@0: PR_IMPLEMENT(PRIntervalTime) PR_SecondsToInterval(PRUint32 seconds) michael@0: { michael@0: return seconds * PR_TicksPerSecond(); michael@0: } /* PR_SecondsToInterval */ michael@0: michael@0: PR_IMPLEMENT(PRIntervalTime) PR_MillisecondsToInterval(PRUint32 milli) michael@0: { michael@0: PRIntervalTime ticks; michael@0: PRUint64 tock, tps, msecPerSec, rounding; michael@0: LL_UI2L(tock, milli); michael@0: LL_I2L(msecPerSec, PR_MSEC_PER_SEC); michael@0: LL_I2L(rounding, (PR_MSEC_PER_SEC >> 1)); michael@0: LL_I2L(tps, PR_TicksPerSecond()); michael@0: LL_MUL(tock, tock, tps); michael@0: LL_ADD(tock, tock, rounding); michael@0: LL_DIV(tock, tock, msecPerSec); michael@0: LL_L2UI(ticks, tock); michael@0: return ticks; michael@0: } /* PR_MillisecondsToInterval */ michael@0: michael@0: PR_IMPLEMENT(PRIntervalTime) PR_MicrosecondsToInterval(PRUint32 micro) michael@0: { michael@0: PRIntervalTime ticks; michael@0: PRUint64 tock, tps, usecPerSec, rounding; michael@0: LL_UI2L(tock, micro); michael@0: LL_I2L(usecPerSec, PR_USEC_PER_SEC); michael@0: LL_I2L(rounding, (PR_USEC_PER_SEC >> 1)); michael@0: LL_I2L(tps, PR_TicksPerSecond()); michael@0: LL_MUL(tock, tock, tps); michael@0: LL_ADD(tock, tock, rounding); michael@0: LL_DIV(tock, tock, usecPerSec); michael@0: LL_L2UI(ticks, tock); michael@0: return ticks; michael@0: } /* PR_MicrosecondsToInterval */ michael@0: michael@0: PR_IMPLEMENT(PRUint32) PR_IntervalToSeconds(PRIntervalTime ticks) michael@0: { michael@0: return ticks / PR_TicksPerSecond(); michael@0: } /* PR_IntervalToSeconds */ michael@0: michael@0: PR_IMPLEMENT(PRUint32) PR_IntervalToMilliseconds(PRIntervalTime ticks) michael@0: { michael@0: PRUint32 milli; michael@0: PRUint64 tock, tps, msecPerSec, rounding; michael@0: LL_UI2L(tock, ticks); michael@0: LL_I2L(msecPerSec, PR_MSEC_PER_SEC); michael@0: LL_I2L(tps, PR_TicksPerSecond()); michael@0: LL_USHR(rounding, tps, 1); michael@0: LL_MUL(tock, tock, msecPerSec); michael@0: LL_ADD(tock, tock, rounding); michael@0: LL_DIV(tock, tock, tps); michael@0: LL_L2UI(milli, tock); michael@0: return milli; michael@0: } /* PR_IntervalToMilliseconds */ michael@0: michael@0: PR_IMPLEMENT(PRUint32) PR_IntervalToMicroseconds(PRIntervalTime ticks) michael@0: { michael@0: PRUint32 micro; michael@0: PRUint64 tock, tps, usecPerSec, rounding; michael@0: LL_UI2L(tock, ticks); michael@0: LL_I2L(usecPerSec, PR_USEC_PER_SEC); michael@0: LL_I2L(tps, PR_TicksPerSecond()); michael@0: LL_USHR(rounding, tps, 1); michael@0: LL_MUL(tock, tock, usecPerSec); michael@0: LL_ADD(tock, tock, rounding); michael@0: LL_DIV(tock, tock, tps); michael@0: LL_L2UI(micro, tock); michael@0: return micro; michael@0: } /* PR_IntervalToMicroseconds */ michael@0: michael@0: /* prinrval.c */ michael@0: