nsprpub/pr/include/prinit.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

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

mercurial