NSPR Reference Previous Contents Next |
NSPR provides an interprocess communication mechanism using a counting semaphore model similar to that which is provided in Unix and Windows platforms.
See also Chapter 28 "Named Shared Memory."
PR_OpenSemaphore
PR_WaitSemaphore
PR_PostSemaphore
PR_CloseSemaphore
PR_DeleteSemaphore
#include <pripcsem.h>
#define PR_SEM_CREATE 0x1 /* create if not exist */
#define PR_SEM_EXCL 0x2 /* fail if already exists */
NSPR_API(PRSem *) PR_OpenSemaphore(
const char *name,
PRIntn flags,
PRIntn mode,
PRUintn value
);
PRSem
structure or NULL
on error.
PR_SEM_CREATE
flag is specified, the
named semaphore is created. The created semaphore needs to be removed from
the system with a PR_DeleteSemaphore
call.
If PR_SEM_CREATE
is specified, the third argument is the access permission bits of
the new semaphore (same interpretation as the mode argument to PR_Open
) and
the fourth argument is the initial value of the new semaphore. If PR_SEM_CREATE
is
not specified, the third and fourth arguments are ignored.
#include <pripcsem.h>
NSPR_API(PRStatus) PR_WaitSemaphore(PRSem *sem);
sem |
A pointer to a PRSem structure returned from a call to
PR_OpenSemaphore .
|
PRStatus
.
PR_WaitSemaphore
tests the value of the semaphore. If the value of the semaphore
is > 0, the value of the semaphore is decremented and the function returns. If the
value of the semaphore is 0, the function blocks until the value becomes > 0, then
the semaphore is decremented and the function returns.
The "test and decrement" operation is performed atomically.
#include <pripcsem.h>
NSPR_API(PRStatus) PR_PostSemaphore(PRSem *sem);
sem |
A pointer to a PRSem structure returned from a call to
PR_OpenSemaphore .
|
PRStatus
#include <pripcsem.h>
NSPR_API(PRStatus) PR_CloseSemaphore(PRSem *sem);
sem |
A pointer to a PRSem structure returned from a call to
PR_OpenSemaphore .
|
PRStatus
.
#include <pripcsem.h>
NSPR_API(PRStatus) PR_DeleteSemaphore(const char *name);
name |
The name of a semaphore that was previously created via a call to
PR_OpenSemaphore .
|
Last Updated May 18, 2001