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