NSPR Reference Previous Contents Next |
Identity and Versioning
Initialization and Cleanup
Module Initialization
#include <prinit.h>
#define PR_NAME "NSPR"
#define PR_VERSION "2.1 yyyymmdd"
typedef PRBool (*PRVersionCheck)(const char*);
#include <prinit.h>
PRBool PR_VersionCheck(const char *importedVersion);
PR_VersionCheck
has one parameter:
|
The version of the shared library being imported.
|
PR_TRUE
.
PR_VersionCheck
tests whether the version of the library being imported
(importedVersion
) is compatible with the running version of the shared library.
This is a string comparison of sorts, though the details of the comparison will vary
over time.
Implicit initialization assumes that the initiator is the primordial thread and that the thread is a user thread of normal priority.
PR_Init
PR_Initialize
PR_Initialized
PR_Cleanup
PR_DisableClockInterrupts
PR_BlockClockInterrupts
PR_UnblockClockInterrupts
PR_SetConcurrency
PR_ProcessExit
PR_Abort
#include <prinit.h>
void PR_Init(
PRThreadType type,
PRThreadPriority priority,
PRUintn maxPTDs);
PR_Init
has these parameters:
type |
This parameter is ignored.
|
priority |
Assigns a priority to the primordial thread.
|
maxPTDs |
This parameter is ignored.
|
PR_Init
is necessary only if a program has specific initialization-sequencing
requirements.
PR_Initialize
implicitly calls PR_Cleanup
on exiting the
primordial function.
#include <prinit.h>
PRIntn PR_Initialize(
PRPrimordialFn prmain,
PRIntn argc,
char **argv,
PRUintn maxPTDs);
PR_Initialize
has these parameters:
prmain
.
PR_Initialize
initializes the NSPR runtime and places NSPR between the caller
and the runtime library. This allows main
to be treated like any other function,
signaling its completion by returning and allowing the runtime to coordinate the
completion of the other threads of the runtime.
PR_Initialize
does not return to its caller until all user threads have terminated.
The type for the root function is specified as follows:
typedef PRIntn (PR_CALLBACK *PRPrimordialFn)(PRIntn argc, char **argv);
The priority of the main (or primordial) thread is PR_PRIORITY_NORMAL
. The thread
may adjust its own priority by using PR_SetThreadPriority
.
#include <prinit.h>
PRBool PR_Initialized(void);
PR_Init
has already been called, PR_TRUE
If PR_Init
has not already been called, PR_FALSE
.
#include <prinit.h>
PRStatus PR_Cleanup(void);
PR_SUCCESS
.
If the calling thread of this function is not the primordial thread, PR_FAILURE
.
PR_Cleanup
must be called by the primordial thread near the end of the main
function.
PR_Cleanup
attempts to synchronize the natural termination of the process. It does
so by blocking the caller, if and only if it is the primordial thread, until all user
threads have terminated. When the primordial thread returns from main
, the
process immediately and silently exits. That is, the process (if necessary) forcibly
terminates any existing threads and exits without significant blocking and without
error messages or core files.
#include <prinit.h>
void PR_DisableClockInterrupts(void);
#include <prinit.h>
void PR_BlockClockInterrupts(void);
#include <prinit.h>
void PR_UnblockClockInterrupts(void);
#include <prinit.h>
void PR_SetConcurrency(PRUintn numCPUs);
PR_SetConcurrency
has one parameter:
numCPUs |
The number of extra virtual processor threads to be created.
|
PR_SetConcurrency
is ignored.
Virtual processors are actually global threads, each of which is designed to support an arbitrary number of local threads. Since global threads are scheduled by the host operating system, this model is particularly applicable to multiprocessor architectures, where true parallelism is possible. However, it may also prove advantageous on uniprocessor systems to reduce the impact of having a locally scheduled thread calling incidental blocking functions. In such cases, all the threads being supported by the virtual processor will block, but those assigned to another virtual processor will be unaffected.
#include <prinit.h>
void PR_ProcessExit(PRIntn status);
PR_ProcessExit
has one parameter:
status |
The exit status code of the process.
|
#include <prinit.h>
void PR_Abort(void);
PR_Abort
results in a core file and a call to the debugger or equivalent, in addition
to causing the entire process to stop.
PR_CallOnce
ensures that such initialization code is
called only once. This facility is recommended in situations where complicated
global initialization is required.
PRCallOnce
PRCallOnceFN
PR_CallOnce
#include <prinit.h>
typedef struct PRCallOnceType {
PRIntn initialized;
PRInt32 inProgress;
PRStatus status;
} PRCallOnceType;
PRCallOnceType
structure to all zeros.
This initialization must be accomplished before any threading issues exist.
#include <prinit.h>
typedef PRStatus (PR_CALLBACK *PRCallOnceFN)(void);
PRStatus
indicating the outcome of the process.
PRStatus PR_CallOnce(
PRCallOnceType *once,
PRCallOnceFN func);
PR_CallOnce
has these parameters:
Last Updated May 18, 2001