prinrval.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. ** File: prinrval.h
  39. ** Description: API to interval timing functions of NSPR.
  40. **
  41. **
  42. ** NSPR provides interval times that are independent of network time
  43. ** of day values. Interval times are (in theory) accurate regardless
  44. ** of host processing requirements and also very cheap to acquire. It
  45. ** is expected that getting an interval time while in a synchronized
  46. ** function (holding one's lock).
  47. **/
  48. #if !defined(prinrval_h)
  49. #define prinrval_h
  50. #include "prtypes.h"
  51. PR_BEGIN_EXTERN_C
  52. /**********************************************************************/
  53. /************************* TYPES AND CONSTANTS ************************/
  54. /**********************************************************************/
  55. typedef PRUint32 PRIntervalTime;
  56. /***********************************************************************
  57. ** DEFINES: PR_INTERVAL_MIN
  58. ** PR_INTERVAL_MAX
  59. ** DESCRIPTION:
  60. ** These two constants define the range (in ticks / second) of the
  61. ** platform dependent type, PRIntervalTime. These constants bound both
  62. ** the period and the resolution of a PRIntervalTime.
  63. ***********************************************************************/
  64. #define PR_INTERVAL_MIN 1000UL
  65. #define PR_INTERVAL_MAX 100000UL
  66. /***********************************************************************
  67. ** DEFINES: PR_INTERVAL_NO_WAIT
  68. ** PR_INTERVAL_NO_TIMEOUT
  69. ** DESCRIPTION:
  70. ** Two reserved constants are defined in the PRIntervalTime namespace.
  71. ** They are used to indicate that the process should wait no time (return
  72. ** immediately) or wait forever (never time out), respectively.
  73. ***********************************************************************/
  74. #define PR_INTERVAL_NO_WAIT 0UL
  75. #define PR_INTERVAL_NO_TIMEOUT 0xffffffffUL
  76. /**********************************************************************/
  77. /****************************** FUNCTIONS *****************************/
  78. /**********************************************************************/
  79. /***********************************************************************
  80. ** FUNCTION: PR_IntervalNow
  81. ** DESCRIPTION:
  82. ** Return the value of NSPR's free running interval timer. That timer
  83. ** can be used to establish epochs and determine intervals (be computing
  84. ** the difference between two times).
  85. ** INPUTS: void
  86. ** OUTPUTS: void
  87. ** RETURN: PRIntervalTime
  88. **
  89. ** SIDE EFFECTS:
  90. ** None
  91. ** RESTRICTIONS:
  92. ** The units of PRIntervalTime are platform dependent. They are chosen
  93. ** such that they are appropriate for the host OS, yet provide sufficient
  94. ** resolution and period to be useful to clients.
  95. ** MEMORY: N/A
  96. ** ALGORITHM: Platform dependent
  97. ***********************************************************************/
  98. NSPR_API(PRIntervalTime) PR_IntervalNow(void);
  99. /***********************************************************************
  100. ** FUNCTION: PR_TicksPerSecond
  101. ** DESCRIPTION:
  102. ** Return the number of ticks per second for PR_IntervalNow's clock.
  103. ** The value will be in the range [PR_INTERVAL_MIN..PR_INTERVAL_MAX].
  104. ** INPUTS: void
  105. ** OUTPUTS: void
  106. ** RETURN: PRUint32
  107. **
  108. ** SIDE EFFECTS:
  109. ** None
  110. ** RESTRICTIONS:
  111. ** None
  112. ** MEMORY: N/A
  113. ** ALGORITHM: N/A
  114. ***********************************************************************/
  115. NSPR_API(PRUint32) PR_TicksPerSecond(void);
  116. /***********************************************************************
  117. ** FUNCTION: PR_SecondsToInterval
  118. ** PR_MillisecondsToInterval
  119. ** PR_MicrosecondsToInterval
  120. ** DESCRIPTION:
  121. ** Convert standard clock units to platform dependent intervals.
  122. ** INPUTS: PRUint32
  123. ** OUTPUTS: void
  124. ** RETURN: PRIntervalTime
  125. **
  126. ** SIDE EFFECTS:
  127. ** None
  128. ** RESTRICTIONS:
  129. ** Conversion may cause overflow, which is not reported.
  130. ** MEMORY: N/A
  131. ** ALGORITHM: N/A
  132. ***********************************************************************/
  133. NSPR_API(PRIntervalTime) PR_SecondsToInterval(PRUint32 seconds);
  134. NSPR_API(PRIntervalTime) PR_MillisecondsToInterval(PRUint32 milli);
  135. NSPR_API(PRIntervalTime) PR_MicrosecondsToInterval(PRUint32 micro);
  136. /***********************************************************************
  137. ** FUNCTION: PR_IntervalToSeconds
  138. ** PR_IntervalToMilliseconds
  139. ** PR_IntervalToMicroseconds
  140. ** DESCRIPTION:
  141. ** Convert platform dependent intervals to standard clock units.
  142. ** INPUTS: PRIntervalTime
  143. ** OUTPUTS: void
  144. ** RETURN: PRUint32
  145. **
  146. ** SIDE EFFECTS:
  147. ** None
  148. ** RESTRICTIONS:
  149. ** Conversion may cause overflow, which is not reported.
  150. ** MEMORY: N/A
  151. ** ALGORITHM: N/A
  152. ***********************************************************************/
  153. NSPR_API(PRUint32) PR_IntervalToSeconds(PRIntervalTime ticks);
  154. NSPR_API(PRUint32) PR_IntervalToMilliseconds(PRIntervalTime ticks);
  155. NSPR_API(PRUint32) PR_IntervalToMicroseconds(PRIntervalTime ticks);
  156. PR_END_EXTERN_C
  157. #endif /* !defined(prinrval_h) */
  158. /* prinrval.h */