Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Side by Side Diff: nspr/pr/src/misc/prinrval.c

Issue 2078763002: Delete bundled copy of NSS and replace with README. (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/nss@master
Patch Set: Delete bundled copy of NSS and replace with README. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « nspr/pr/src/misc/prinit.c ('k') | nspr/pr/src/misc/pripc.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 void _PR_InitClock(void)
23 {
24 _PR_MD_INTERVAL_INIT();
25 #ifdef DEBUG
26 {
27 PRIntervalTime ticksPerSec = PR_TicksPerSecond();
28
29 PR_ASSERT(ticksPerSec >= PR_INTERVAL_MIN);
30 PR_ASSERT(ticksPerSec <= PR_INTERVAL_MAX);
31 }
32 #endif /* DEBUG */
33 }
34
35 PR_IMPLEMENT(PRIntervalTime) PR_IntervalNow(void)
36 {
37 if (!_pr_initialized) _PR_ImplicitInitialization();
38 return _PR_MD_GET_INTERVAL();
39 } /* PR_IntervalNow */
40
41 PR_EXTERN(PRUint32) PR_TicksPerSecond(void)
42 {
43 if (!_pr_initialized) _PR_ImplicitInitialization();
44 return _PR_MD_INTERVAL_PER_SEC();
45 } /* PR_TicksPerSecond */
46
47 PR_IMPLEMENT(PRIntervalTime) PR_SecondsToInterval(PRUint32 seconds)
48 {
49 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 LL_UI2L(tock, milli);
57 LL_I2L(msecPerSec, PR_MSEC_PER_SEC);
58 LL_I2L(rounding, (PR_MSEC_PER_SEC >> 1));
59 LL_I2L(tps, PR_TicksPerSecond());
60 LL_MUL(tock, tock, tps);
61 LL_ADD(tock, tock, rounding);
62 LL_DIV(tock, tock, msecPerSec);
63 LL_L2UI(ticks, tock);
64 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 LL_UI2L(tock, micro);
72 LL_I2L(usecPerSec, PR_USEC_PER_SEC);
73 LL_I2L(rounding, (PR_USEC_PER_SEC >> 1));
74 LL_I2L(tps, PR_TicksPerSecond());
75 LL_MUL(tock, tock, tps);
76 LL_ADD(tock, tock, rounding);
77 LL_DIV(tock, tock, usecPerSec);
78 LL_L2UI(ticks, tock);
79 return ticks;
80 } /* PR_MicrosecondsToInterval */
81
82 PR_IMPLEMENT(PRUint32) PR_IntervalToSeconds(PRIntervalTime ticks)
83 {
84 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 LL_UI2L(tock, ticks);
92 LL_I2L(msecPerSec, PR_MSEC_PER_SEC);
93 LL_I2L(tps, PR_TicksPerSecond());
94 LL_USHR(rounding, tps, 1);
95 LL_MUL(tock, tock, msecPerSec);
96 LL_ADD(tock, tock, rounding);
97 LL_DIV(tock, tock, tps);
98 LL_L2UI(milli, tock);
99 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 LL_UI2L(tock, ticks);
107 LL_I2L(usecPerSec, PR_USEC_PER_SEC);
108 LL_I2L(tps, PR_TicksPerSecond());
109 LL_USHR(rounding, tps, 1);
110 LL_MUL(tock, tock, usecPerSec);
111 LL_ADD(tock, tock, rounding);
112 LL_DIV(tock, tock, tps);
113 LL_L2UI(micro, tock);
114 return micro;
115 } /* PR_IntervalToMicroseconds */
116
117 /* prinrval.c */
118
OLDNEW
« no previous file with comments | « nspr/pr/src/misc/prinit.c ('k') | nspr/pr/src/misc/pripc.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698