prinit.h 7.8 KB

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