Coverage Report

Created: 2026-06-07 07:11

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