1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is the Netscape Portable Runtime (NSPR).
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
40 ** Description: API to interval timing functions of NSPR.
43 ** NSPR provides interval times that are independent of network time
44 ** of day values. Interval times are (in theory) accurate regardless
45 ** of host processing requirements and also very cheap to acquire. It
46 ** is expected that getting an interval time while in a synchronized
47 ** function (holding one's lock).
50 #if !defined(prinrval_h)
57 /**********************************************************************/
58 /************************* TYPES AND CONSTANTS ************************/
59 /**********************************************************************/
61 typedef PRUint32 PRIntervalTime;
63 /***********************************************************************
64 ** DEFINES: PR_INTERVAL_MIN
67 ** These two constants define the range (in ticks / second) of the
68 ** platform dependent type, PRIntervalTime. These constants bound both
69 ** the period and the resolution of a PRIntervalTime.
70 ***********************************************************************/
71 #define PR_INTERVAL_MIN 1000UL
72 #define PR_INTERVAL_MAX 100000UL
74 /***********************************************************************
75 ** DEFINES: PR_INTERVAL_NO_WAIT
76 ** PR_INTERVAL_NO_TIMEOUT
78 ** Two reserved constants are defined in the PRIntervalTime namespace.
79 ** They are used to indicate that the process should wait no time (return
80 ** immediately) or wait forever (never time out), respectively.
81 ** Note: PR_INTERVAL_NO_TIMEOUT passed as input to PR_Connect is
82 ** interpreted as use the OS's connect timeout.
84 ***********************************************************************/
85 #define PR_INTERVAL_NO_WAIT 0UL
86 #define PR_INTERVAL_NO_TIMEOUT 0xffffffffUL
88 /**********************************************************************/
89 /****************************** FUNCTIONS *****************************/
90 /**********************************************************************/
92 /***********************************************************************
93 ** FUNCTION: PR_IntervalNow
95 ** Return the value of NSPR's free running interval timer. That timer
96 ** can be used to establish epochs and determine intervals (be computing
97 ** the difference between two times).
100 ** RETURN: PRIntervalTime
105 ** The units of PRIntervalTime are platform dependent. They are chosen
106 ** such that they are appropriate for the host OS, yet provide sufficient
107 ** resolution and period to be useful to clients.
109 ** ALGORITHM: Platform dependent
110 ***********************************************************************/
111 NSPR_API(PRIntervalTime) PR_IntervalNow(void);
113 /***********************************************************************
114 ** FUNCTION: PR_TicksPerSecond
116 ** Return the number of ticks per second for PR_IntervalNow's clock.
117 ** The value will be in the range [PR_INTERVAL_MIN..PR_INTERVAL_MAX].
128 ***********************************************************************/
129 NSPR_API(PRUint32) PR_TicksPerSecond(void);
131 /***********************************************************************
132 ** FUNCTION: PR_SecondsToInterval
133 ** PR_MillisecondsToInterval
134 ** PR_MicrosecondsToInterval
136 ** Convert standard clock units to platform dependent intervals.
139 ** RETURN: PRIntervalTime
144 ** Conversion may cause overflow, which is not reported.
147 ***********************************************************************/
148 NSPR_API(PRIntervalTime) PR_SecondsToInterval(PRUint32 seconds);
149 NSPR_API(PRIntervalTime) PR_MillisecondsToInterval(PRUint32 milli);
150 NSPR_API(PRIntervalTime) PR_MicrosecondsToInterval(PRUint32 micro);
152 /***********************************************************************
153 ** FUNCTION: PR_IntervalToSeconds
154 ** PR_IntervalToMilliseconds
155 ** PR_IntervalToMicroseconds
157 ** Convert platform dependent intervals to standard clock units.
158 ** INPUTS: PRIntervalTime
165 ** Conversion may cause overflow, which is not reported.
168 ***********************************************************************/
169 NSPR_API(PRUint32) PR_IntervalToSeconds(PRIntervalTime ticks);
170 NSPR_API(PRUint32) PR_IntervalToMilliseconds(PRIntervalTime ticks);
171 NSPR_API(PRUint32) PR_IntervalToMicroseconds(PRIntervalTime ticks);
176 #endif /* !defined(prinrval_h) */