Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : /*
7 : * file: prinrval.c
8 : * description: implementation for the kernel interval timing functions
9 : */
10 :
11 : #include "primpl.h"
12 :
13 : /*
14 : *-----------------------------------------------------------------------
15 : *
16 : * _PR_InitClock --
17 : *
18 : *
19 : *-----------------------------------------------------------------------
20 : */
21 :
22 3 : void _PR_InitClock(void)
23 : {
24 : _PR_MD_INTERVAL_INIT();
25 : #ifdef DEBUG
26 : {
27 3 : PRIntervalTime ticksPerSec = PR_TicksPerSecond();
28 :
29 3 : PR_ASSERT(ticksPerSec >= PR_INTERVAL_MIN);
30 3 : PR_ASSERT(ticksPerSec <= PR_INTERVAL_MAX);
31 : }
32 : #endif /* DEBUG */
33 3 : }
34 :
35 : PR_IMPLEMENT(PRIntervalTime) PR_IntervalNow(void)
36 : {
37 4527 : if (!_pr_initialized) _PR_ImplicitInitialization();
38 4527 : return _PR_MD_GET_INTERVAL();
39 : } /* PR_IntervalNow */
40 :
41 : PR_EXTERN(PRUint32) PR_TicksPerSecond(void)
42 : {
43 2052 : if (!_pr_initialized) _PR_ImplicitInitialization();
44 2052 : return _PR_MD_INTERVAL_PER_SEC();
45 : } /* PR_TicksPerSecond */
46 :
47 : PR_IMPLEMENT(PRIntervalTime) PR_SecondsToInterval(PRUint32 seconds)
48 : {
49 42 : return seconds * PR_TicksPerSecond();
50 : } /* PR_SecondsToInterval */
51 :
52 : PR_IMPLEMENT(PRIntervalTime) PR_MillisecondsToInterval(PRUint32 milli)
53 : {
54 : PRIntervalTime ticks;
55 : PRUint64 tock, tps, msecPerSec, rounding;
56 1323 : LL_UI2L(tock, milli);
57 1323 : LL_I2L(msecPerSec, PR_MSEC_PER_SEC);
58 1323 : LL_I2L(rounding, (PR_MSEC_PER_SEC >> 1));
59 1323 : LL_I2L(tps, PR_TicksPerSecond());
60 1323 : LL_MUL(tock, tock, tps);
61 1323 : LL_ADD(tock, tock, rounding);
62 1323 : LL_DIV(tock, tock, msecPerSec);
63 1323 : LL_L2UI(ticks, tock);
64 1323 : return ticks;
65 : } /* PR_MillisecondsToInterval */
66 :
67 : PR_IMPLEMENT(PRIntervalTime) PR_MicrosecondsToInterval(PRUint32 micro)
68 : {
69 : PRIntervalTime ticks;
70 : PRUint64 tock, tps, usecPerSec, rounding;
71 384 : LL_UI2L(tock, micro);
72 384 : LL_I2L(usecPerSec, PR_USEC_PER_SEC);
73 384 : LL_I2L(rounding, (PR_USEC_PER_SEC >> 1));
74 384 : LL_I2L(tps, PR_TicksPerSecond());
75 384 : LL_MUL(tock, tock, tps);
76 384 : LL_ADD(tock, tock, rounding);
77 384 : LL_DIV(tock, tock, usecPerSec);
78 384 : LL_L2UI(ticks, tock);
79 384 : return ticks;
80 : } /* PR_MicrosecondsToInterval */
81 :
82 : PR_IMPLEMENT(PRUint32) PR_IntervalToSeconds(PRIntervalTime ticks)
83 : {
84 60 : return ticks / PR_TicksPerSecond();
85 : } /* PR_IntervalToSeconds */
86 :
87 : PR_IMPLEMENT(PRUint32) PR_IntervalToMilliseconds(PRIntervalTime ticks)
88 : {
89 : PRUint32 milli;
90 : PRUint64 tock, tps, msecPerSec, rounding;
91 14 : LL_UI2L(tock, ticks);
92 14 : LL_I2L(msecPerSec, PR_MSEC_PER_SEC);
93 14 : LL_I2L(tps, PR_TicksPerSecond());
94 14 : LL_USHR(rounding, tps, 1);
95 14 : LL_MUL(tock, tock, msecPerSec);
96 14 : LL_ADD(tock, tock, rounding);
97 14 : LL_DIV(tock, tock, tps);
98 14 : LL_L2UI(milli, tock);
99 14 : return milli;
100 : } /* PR_IntervalToMilliseconds */
101 :
102 : PR_IMPLEMENT(PRUint32) PR_IntervalToMicroseconds(PRIntervalTime ticks)
103 : {
104 : PRUint32 micro;
105 : PRUint64 tock, tps, usecPerSec, rounding;
106 162 : LL_UI2L(tock, ticks);
107 162 : LL_I2L(usecPerSec, PR_USEC_PER_SEC);
108 162 : LL_I2L(tps, PR_TicksPerSecond());
109 162 : LL_USHR(rounding, tps, 1);
110 162 : LL_MUL(tock, tock, usecPerSec);
111 162 : LL_ADD(tock, tock, rounding);
112 162 : LL_DIV(tock, tock, tps);
113 162 : LL_L2UI(micro, tock);
114 162 : return micro;
115 : } /* PR_IntervalToMicroseconds */
116 :
117 : /* prinrval.c */
118 :
|