prinit.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. #ifndef prinit_h___
  6. #define prinit_h___
  7. #include "prthread.h"
  8. #include "prtypes.h"
  9. #include "prwin16.h"
  10. #include <stdio.h>
  11. PR_BEGIN_EXTERN_C
  12. /************************************************************************/
  13. /**************************IDENTITY AND VERSIONING***********************/
  14. /************************************************************************/
  15. /*
  16. ** NSPR's name, this should persist until at least the turn of the
  17. ** century.
  18. */
  19. #define PR_NAME "NSPR"
  20. /*
  21. ** NSPR's version is used to determine the likelihood that the version you
  22. ** used to build your component is anywhere close to being compatible with
  23. ** what is in the underlying library.
  24. **
  25. ** The format of the version string is
  26. ** "<major version>.<minor version>[.<patch level>] [<Beta>]"
  27. */
  28. #define PR_VERSION "4.25"
  29. #define PR_VMAJOR 4
  30. #define PR_VMINOR 25
  31. #define PR_VPATCH 0
  32. #define PR_BETA PR_FALSE
  33. /*
  34. ** PRVersionCheck
  35. **
  36. ** The basic signature of the function that is called to provide version
  37. ** checking. The result will be a boolean that indicates the likelihood
  38. ** that the underling library will perform as the caller expects.
  39. **
  40. ** The only argument is a string, which should be the verson identifier
  41. ** of the library in question. That string will be compared against an
  42. ** equivalent string that represents the actual build version of the
  43. ** exporting library.
  44. **
  45. ** The result will be the logical union of the directly called library
  46. ** and all dependent libraries.
  47. */
  48. typedef PRBool (*PRVersionCheck)(const char*);
  49. /*
  50. ** PR_VersionCheck
  51. **
  52. ** NSPR's existance proof of the version check function.
  53. **
  54. ** Note that NSPR has no cooperating dependencies.
  55. */
  56. NSPR_API(PRBool) PR_VersionCheck(const char *importedVersion);
  57. /*
  58. * Returns a const string of the NSPR library version.
  59. */
  60. NSPR_API(const char*) PR_GetVersion(void);
  61. /************************************************************************/
  62. /*******************************INITIALIZATION***************************/
  63. /************************************************************************/
  64. /*
  65. ** Initialize the runtime. Attach a thread object to the currently
  66. ** executing native thread of type "type".
  67. **
  68. ** The specificaiton of 'maxPTDs' is ignored.
  69. */
  70. NSPR_API(void) PR_Init(
  71. PRThreadType type, PRThreadPriority priority, PRUintn maxPTDs);
  72. /*
  73. ** And alternate form of initialization, one that may become the default if
  74. ** not the only mechanism, provides a method to get the NSPR runtime init-
  75. ** ialized and place NSPR between the caller and the runtime library. This
  76. ** allows main() to be treated as any other thread root function, signalling
  77. ** its compeletion by returning and allowing the runtime to coordinate the
  78. ** completion of the other threads of the runtime.
  79. **
  80. ** The priority of the main (or primordial) thread will be PR_PRIORITY_NORMAL.
  81. ** The thread may adjust its own priority by using PR_SetPriority(), though
  82. ** at this time the support for priorities is somewhat weak.
  83. **
  84. ** The specificaiton of 'maxPTDs' is ignored.
  85. **
  86. ** The value returned by PR_Initialize is the value returned from the root
  87. ** function, 'prmain'.
  88. */
  89. typedef PRIntn (PR_CALLBACK *PRPrimordialFn)(PRIntn argc, char **argv);
  90. NSPR_API(PRIntn) PR_Initialize(
  91. PRPrimordialFn prmain, PRIntn argc, char **argv, PRUintn maxPTDs);
  92. /*
  93. ** Return PR_TRUE if PR_Init has already been called.
  94. */
  95. NSPR_API(PRBool) PR_Initialized(void);
  96. /*
  97. * Perform a graceful shutdown of NSPR. PR_Cleanup() may be called by
  98. * the primordial thread near the end of the main() function.
  99. *
  100. * PR_Cleanup() attempts to synchronize the natural termination of
  101. * process. It does that by blocking the caller, if and only if it is
  102. * the primordial thread, until the number of user threads has dropped
  103. * to zero. When the primordial thread returns from main(), the process
  104. * will immediately and silently exit. That is, it will (if necessary)
  105. * forcibly terminate any existing threads and exit without significant
  106. * blocking and there will be no error messages or core files.
  107. *
  108. * PR_Cleanup() returns PR_SUCCESS if NSPR is successfully shutdown,
  109. * or PR_FAILURE if the calling thread of this function is not the
  110. * primordial thread.
  111. */
  112. NSPR_API(PRStatus) PR_Cleanup(void);
  113. /*
  114. ** Disable Interrupts
  115. ** Disables timer signals used for pre-emptive scheduling.
  116. */
  117. NSPR_API(void) PR_DisableClockInterrupts(void);
  118. /*
  119. ** Enables Interrupts
  120. ** Enables timer signals used for pre-emptive scheduling.
  121. */
  122. NSPR_API(void) PR_EnableClockInterrupts(void);
  123. /*
  124. ** Block Interrupts
  125. ** Blocks the timer signal used for pre-emptive scheduling
  126. */
  127. NSPR_API(void) PR_BlockClockInterrupts(void);
  128. /*
  129. ** Unblock Interrupts
  130. ** Unblocks the timer signal used for pre-emptive scheduling
  131. */
  132. NSPR_API(void) PR_UnblockClockInterrupts(void);
  133. /*
  134. ** Create extra virtual processor threads. Generally used with MP systems.
  135. */
  136. NSPR_API(void) PR_SetConcurrency(PRUintn numCPUs);
  137. /*
  138. ** Control the method and size of the file descriptor (PRFileDesc*)
  139. ** cache used by the runtime. Setting 'high' to zero is for performance,
  140. ** any other value probably for debugging (see memo on FD caching).
  141. */
  142. NSPR_API(PRStatus) PR_SetFDCacheSize(PRIntn low, PRIntn high);
  143. /*
  144. * Cause an immediate, nongraceful, forced termination of the process.
  145. * It takes a PRIntn argument, which is the exit status code of the
  146. * process.
  147. */
  148. NSPR_API(void) PR_ProcessExit(PRIntn status);
  149. /*
  150. ** Abort the process in a non-graceful manner. This will cause a core file,
  151. ** call to the debugger or other moral equivalent as well as causing the
  152. ** entire process to stop.
  153. */
  154. NSPR_API(void) PR_Abort(void);
  155. /*
  156. ****************************************************************
  157. *
  158. * Module initialization:
  159. *
  160. ****************************************************************
  161. */
  162. typedef struct PRCallOnceType {
  163. PRIntn initialized;
  164. PRInt32 inProgress;
  165. PRStatus status;
  166. } PRCallOnceType;
  167. typedef PRStatus (PR_CALLBACK *PRCallOnceFN)(void);
  168. typedef PRStatus (PR_CALLBACK *PRCallOnceWithArgFN)(void *arg);
  169. NSPR_API(PRStatus) PR_CallOnce(
  170. PRCallOnceType *once,
  171. PRCallOnceFN func
  172. );
  173. NSPR_API(PRStatus) PR_CallOnceWithArg(
  174. PRCallOnceType *once,
  175. PRCallOnceWithArgFN func,
  176. void *arg
  177. );
  178. PR_END_EXTERN_C
  179. #endif /* prinit_h___ */