prinrval.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /*
  6. ** File: prinrval.h
  7. ** Description: API to interval timing functions of NSPR.
  8. **
  9. **
  10. ** NSPR provides interval times that are independent of network time
  11. ** of day values. Interval times are (in theory) accurate regardless
  12. ** of host processing requirements and also very cheap to acquire. It
  13. ** is expected that getting an interval time while in a synchronized
  14. ** function (holding one's lock).
  15. **/
  16. #if !defined(prinrval_h)
  17. #define prinrval_h
  18. #include "prtypes.h"
  19. PR_BEGIN_EXTERN_C
  20. /**********************************************************************/
  21. /************************* TYPES AND CONSTANTS ************************/
  22. /**********************************************************************/
  23. typedef PRUint32 PRIntervalTime;
  24. /***********************************************************************
  25. ** DEFINES: PR_INTERVAL_MIN
  26. ** PR_INTERVAL_MAX
  27. ** DESCRIPTION:
  28. ** These two constants define the range (in ticks / second) of the
  29. ** platform dependent type, PRIntervalTime. These constants bound both
  30. ** the period and the resolution of a PRIntervalTime.
  31. ***********************************************************************/
  32. #define PR_INTERVAL_MIN 1000UL
  33. #define PR_INTERVAL_MAX 100000UL
  34. /***********************************************************************
  35. ** DEFINES: PR_INTERVAL_NO_WAIT
  36. ** PR_INTERVAL_NO_TIMEOUT
  37. ** DESCRIPTION:
  38. ** Two reserved constants are defined in the PRIntervalTime namespace.
  39. ** They are used to indicate that the process should wait no time (return
  40. ** immediately) or wait forever (never time out), respectively.
  41. ** Note: PR_INTERVAL_NO_TIMEOUT passed as input to PR_Connect is
  42. ** interpreted as use the OS's connect timeout.
  43. **
  44. ***********************************************************************/
  45. #define PR_INTERVAL_NO_WAIT 0UL
  46. #define PR_INTERVAL_NO_TIMEOUT 0xffffffffUL
  47. /**********************************************************************/
  48. /****************************** FUNCTIONS *****************************/
  49. /**********************************************************************/
  50. /***********************************************************************
  51. ** FUNCTION: PR_IntervalNow
  52. ** DESCRIPTION:
  53. ** Return the value of NSPR's free running interval timer. That timer
  54. ** can be used to establish epochs and determine intervals (be computing
  55. ** the difference between two times).
  56. ** INPUTS: void
  57. ** OUTPUTS: void
  58. ** RETURN: PRIntervalTime
  59. **
  60. ** SIDE EFFECTS:
  61. ** None
  62. ** RESTRICTIONS:
  63. ** The units of PRIntervalTime are platform dependent. They are chosen
  64. ** such that they are appropriate for the host OS, yet provide sufficient
  65. ** resolution and period to be useful to clients.
  66. ** MEMORY: N/A
  67. ** ALGORITHM: Platform dependent
  68. ***********************************************************************/
  69. NSPR_API(PRIntervalTime) PR_IntervalNow(void);
  70. /***********************************************************************
  71. ** FUNCTION: PR_TicksPerSecond
  72. ** DESCRIPTION:
  73. ** Return the number of ticks per second for PR_IntervalNow's clock.
  74. ** The value will be in the range [PR_INTERVAL_MIN..PR_INTERVAL_MAX].
  75. ** INPUTS: void
  76. ** OUTPUTS: void
  77. ** RETURN: PRUint32
  78. **
  79. ** SIDE EFFECTS:
  80. ** None
  81. ** RESTRICTIONS:
  82. ** None
  83. ** MEMORY: N/A
  84. ** ALGORITHM: N/A
  85. ***********************************************************************/
  86. NSPR_API(PRUint32) PR_TicksPerSecond(void);
  87. /***********************************************************************
  88. ** FUNCTION: PR_SecondsToInterval
  89. ** PR_MillisecondsToInterval
  90. ** PR_MicrosecondsToInterval
  91. ** DESCRIPTION:
  92. ** Convert standard clock units to platform dependent intervals.
  93. ** INPUTS: PRUint32
  94. ** OUTPUTS: void
  95. ** RETURN: PRIntervalTime
  96. **
  97. ** SIDE EFFECTS:
  98. ** None
  99. ** RESTRICTIONS:
  100. ** Conversion may cause overflow, which is not reported.
  101. ** MEMORY: N/A
  102. ** ALGORITHM: N/A
  103. ***********************************************************************/
  104. NSPR_API(PRIntervalTime) PR_SecondsToInterval(PRUint32 seconds);
  105. NSPR_API(PRIntervalTime) PR_MillisecondsToInterval(PRUint32 milli);
  106. NSPR_API(PRIntervalTime) PR_MicrosecondsToInterval(PRUint32 micro);
  107. /***********************************************************************
  108. ** FUNCTION: PR_IntervalToSeconds
  109. ** PR_IntervalToMilliseconds
  110. ** PR_IntervalToMicroseconds
  111. ** DESCRIPTION:
  112. ** Convert platform dependent intervals to standard clock units.
  113. ** INPUTS: PRIntervalTime
  114. ** OUTPUTS: void
  115. ** RETURN: PRUint32
  116. **
  117. ** SIDE EFFECTS:
  118. ** None
  119. ** RESTRICTIONS:
  120. ** Conversion may cause overflow, which is not reported.
  121. ** MEMORY: N/A
  122. ** ALGORITHM: N/A
  123. ***********************************************************************/
  124. NSPR_API(PRUint32) PR_IntervalToSeconds(PRIntervalTime ticks);
  125. NSPR_API(PRUint32) PR_IntervalToMilliseconds(PRIntervalTime ticks);
  126. NSPR_API(PRUint32) PR_IntervalToMicroseconds(PRIntervalTime ticks);
  127. PR_END_EXTERN_C
  128. #endif /* !defined(prinrval_h) */
  129. /* prinrval.h */