home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / prinrval.h < prev    next >
C/C++ Source or Header  |  1998-07-21  |  6KB  |  157 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /*
  20. ** File:        prinrval.h
  21. ** Description:    API to interval timing functions of NSPR.
  22. **
  23. **
  24. ** NSPR provides interval times that are independent of network time
  25. ** of day values. Interval times are (in theory) accurate regardless
  26. ** of host processing requirements and also very cheap to acquire. It
  27. ** is expected that getting an interval time while in a synchronized
  28. ** function (holding one's lock).
  29. **/
  30.  
  31. #if !defined(prinrval_h)
  32. #define prinrval_h
  33.  
  34. #include "prtypes.h"
  35.  
  36. PR_BEGIN_EXTERN_C
  37.  
  38. /**********************************************************************/
  39. /************************* TYPES AND CONSTANTS ************************/
  40. /**********************************************************************/
  41.  
  42. typedef PRUint32 PRIntervalTime;
  43.  
  44. /***********************************************************************
  45. ** DEFINES:     PR_INTERVAL_MIN
  46. **              PR_INTERVAL_MAX
  47. ** DESCRIPTION:
  48. **  These two constants define the range (in ticks / second) of the
  49. **  platform dependent type, PRIntervalTime. These constants bound both
  50. **  the period and the resolution of a PRIntervalTime. 
  51. ***********************************************************************/
  52. #define PR_INTERVAL_MIN 1000UL
  53. #define PR_INTERVAL_MAX 100000UL
  54.  
  55. /***********************************************************************
  56. ** DEFINES:     PR_INTERVAL_NO_WAIT
  57. **              PR_INTERVAL_NO_TIMEOUT
  58. ** DESCRIPTION:
  59. **  Two reserved constants are defined in the PRIntervalTime namespace.
  60. **  They are used to indicate that the process should wait no time (return
  61. **  immediately) or wait forever (never time out), respectively.
  62. ***********************************************************************/
  63. #define PR_INTERVAL_NO_WAIT 0UL
  64. #define PR_INTERVAL_NO_TIMEOUT 0xffffffffUL
  65.  
  66. /**********************************************************************/
  67. /****************************** FUNCTIONS *****************************/
  68. /**********************************************************************/
  69.  
  70. /***********************************************************************
  71. ** FUNCTION:    PR_IntervalNow
  72. ** DESCRIPTION:
  73. **  Return the value of NSPR's free running interval timer. That timer
  74. **  can be used to establish epochs and determine intervals (be computing
  75. **  the difference between two times).
  76. ** INPUTS:      void
  77. ** OUTPUTS:     void
  78. ** RETURN:      PRIntervalTime
  79. **  
  80. ** SIDE EFFECTS:
  81. **  None
  82. ** RESTRICTIONS:
  83. **  The units of PRIntervalTime are platform dependent. They are chosen
  84. **  such that they are appropriate for the host OS, yet provide sufficient
  85. **  resolution and period to be useful to clients. 
  86. ** MEMORY:      N/A
  87. ** ALGORITHM:   Platform dependent
  88. ***********************************************************************/
  89. PR_EXTERN(PRIntervalTime) PR_IntervalNow(void);
  90.  
  91. /***********************************************************************
  92. ** FUNCTION:    PR_TicksPerSecond
  93. ** DESCRIPTION:
  94. **  Return the number of ticks per second for PR_IntervalNow's clock.
  95. **  The value will be in the range [PR_INTERVAL_MIN..PR_INTERVAL_MAX].
  96. ** INPUTS:      void
  97. ** OUTPUTS:     void
  98. ** RETURN:      PRUint32
  99. **  
  100. ** SIDE EFFECTS:
  101. **  None
  102. ** RESTRICTIONS:
  103. **  None
  104. ** MEMORY:      N/A
  105. ** ALGORITHM:   N/A
  106. ***********************************************************************/
  107. PR_EXTERN(PRUint32) PR_TicksPerSecond(void);
  108.  
  109. /***********************************************************************
  110. ** FUNCTION:    PR_SecondsToInterval
  111. **              PR_MillisecondsToInterval
  112. **              PR_MicrosecondsToInterval
  113. ** DESCRIPTION:
  114. **  Convert standard clock units to platform dependent intervals.
  115. ** INPUTS:      PRUint32
  116. ** OUTPUTS:     void
  117. ** RETURN:      PRIntervalTime
  118. **  
  119. ** SIDE EFFECTS:
  120. **  None
  121. ** RESTRICTIONS:
  122. **  Conversion may cause overflow, which is not reported.
  123. ** MEMORY:      N/A
  124. ** ALGORITHM:   N/A
  125. ***********************************************************************/
  126. PR_EXTERN(PRIntervalTime) PR_SecondsToInterval(PRUint32 seconds);
  127. PR_EXTERN(PRIntervalTime) PR_MillisecondsToInterval(PRUint32 milli);
  128. PR_EXTERN(PRIntervalTime) PR_MicrosecondsToInterval(PRUint32 micro);
  129.  
  130. /***********************************************************************
  131. ** FUNCTION:    PR_IntervalToSeconds
  132. **              PR_IntervalToMilliseconds
  133. **              PR_IntervalToMicroseconds
  134. ** DESCRIPTION:
  135. **  Convert platform dependent intervals to standard clock units.
  136. ** INPUTS:      PRIntervalTime
  137. ** OUTPUTS:     void
  138. ** RETURN:      PRUint32
  139. **  
  140. ** SIDE EFFECTS:
  141. **  None
  142. ** RESTRICTIONS:
  143. **  Conversion may cause overflow, which is not reported.
  144. ** MEMORY:      N/A
  145. ** ALGORITHM:   N/A
  146. ***********************************************************************/
  147. PR_EXTERN(PRUint32) PR_IntervalToSeconds(PRIntervalTime ticks);
  148. PR_EXTERN(PRUint32) PR_IntervalToMilliseconds(PRIntervalTime ticks);
  149. PR_EXTERN(PRUint32) PR_IntervalToMicroseconds(PRIntervalTime ticks);
  150.  
  151. PR_END_EXTERN_C
  152.  
  153.  
  154. #endif /* !defined(prinrval_h) */
  155.  
  156. /* prinrval.h */
  157.