Upload Tizen:Base source
[toolchains/nspr.git] / mozilla / nsprpub / pr / include / prinrval.h
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
4  *
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/
9  *
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
13  * License.
14  *
15  * The Original Code is the Netscape Portable Runtime (NSPR).
16  *
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.
21  *
22  * Contributor(s):
23  *
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.
35  *
36  * ***** END LICENSE BLOCK ***** */
37
38 /*
39 ** File:                prinrval.h
40 ** Description: API to interval timing functions of NSPR.
41 **
42 **
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).
48 **/
49
50 #if !defined(prinrval_h)
51 #define prinrval_h
52
53 #include "prtypes.h"
54
55 PR_BEGIN_EXTERN_C
56
57 /**********************************************************************/
58 /************************* TYPES AND CONSTANTS ************************/
59 /**********************************************************************/
60
61 typedef PRUint32 PRIntervalTime;
62
63 /***********************************************************************
64 ** DEFINES:     PR_INTERVAL_MIN
65 **              PR_INTERVAL_MAX
66 ** DESCRIPTION:
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
73
74 /***********************************************************************
75 ** DEFINES:     PR_INTERVAL_NO_WAIT
76 **              PR_INTERVAL_NO_TIMEOUT
77 ** DESCRIPTION:
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.
83 **  
84 ***********************************************************************/
85 #define PR_INTERVAL_NO_WAIT 0UL
86 #define PR_INTERVAL_NO_TIMEOUT 0xffffffffUL
87
88 /**********************************************************************/
89 /****************************** FUNCTIONS *****************************/
90 /**********************************************************************/
91
92 /***********************************************************************
93 ** FUNCTION:    PR_IntervalNow
94 ** DESCRIPTION:
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).
98 ** INPUTS:      void
99 ** OUTPUTS:     void
100 ** RETURN:      PRIntervalTime
101 **  
102 ** SIDE EFFECTS:
103 **  None
104 ** RESTRICTIONS:
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. 
108 ** MEMORY:      N/A
109 ** ALGORITHM:   Platform dependent
110 ***********************************************************************/
111 NSPR_API(PRIntervalTime) PR_IntervalNow(void);
112
113 /***********************************************************************
114 ** FUNCTION:    PR_TicksPerSecond
115 ** DESCRIPTION:
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].
118 ** INPUTS:      void
119 ** OUTPUTS:     void
120 ** RETURN:      PRUint32
121 **  
122 ** SIDE EFFECTS:
123 **  None
124 ** RESTRICTIONS:
125 **  None
126 ** MEMORY:      N/A
127 ** ALGORITHM:   N/A
128 ***********************************************************************/
129 NSPR_API(PRUint32) PR_TicksPerSecond(void);
130
131 /***********************************************************************
132 ** FUNCTION:    PR_SecondsToInterval
133 **              PR_MillisecondsToInterval
134 **              PR_MicrosecondsToInterval
135 ** DESCRIPTION:
136 **  Convert standard clock units to platform dependent intervals.
137 ** INPUTS:      PRUint32
138 ** OUTPUTS:     void
139 ** RETURN:      PRIntervalTime
140 **  
141 ** SIDE EFFECTS:
142 **  None
143 ** RESTRICTIONS:
144 **  Conversion may cause overflow, which is not reported.
145 ** MEMORY:      N/A
146 ** ALGORITHM:   N/A
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);
151
152 /***********************************************************************
153 ** FUNCTION:    PR_IntervalToSeconds
154 **              PR_IntervalToMilliseconds
155 **              PR_IntervalToMicroseconds
156 ** DESCRIPTION:
157 **  Convert platform dependent intervals to standard clock units.
158 ** INPUTS:      PRIntervalTime
159 ** OUTPUTS:     void
160 ** RETURN:      PRUint32
161 **  
162 ** SIDE EFFECTS:
163 **  None
164 ** RESTRICTIONS:
165 **  Conversion may cause overflow, which is not reported.
166 ** MEMORY:      N/A
167 ** ALGORITHM:   N/A
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);
172
173 PR_END_EXTERN_C
174
175
176 #endif /* !defined(prinrval_h) */
177
178 /* prinrval.h */