NSPR Reference Previous Contents Next |
PRLock
.
In NSPR, a mutex of type PRLock
controls locking, and associated condition
variables communicate changes in state among threads. When a programmer
associates a mutex with an arbitrary collection of data, the mutex provides a
protective monitor around the data.
In general, a monitor is a conceptual entity composed of a mutex, one or more
condition variables, and the monitored data. Monitors in this generic sense should
not be confused with monitors used in Java programming. In addition to PRLock
,
NSPR provides another mutex type, PRMonitor
, which is reentrant and can have
only one associated condition variable. PRMonitor
is intended for use with Java
and reflects the Java approach to thread synchronization.
For an introduction to NSPR thread synchronization, including locks and condition variables, see Chapter 1 "Introduction to NSPR"
For reference information on NSPR condition variables, see Chapter 6 "Condition Variables"
#include <prlock.h>
typedef struct PRLock PRLock;
PR_NewLock
creates a new lock object.
PR_DestroyLock
destroys a specified lock object.
PR_Lock
locks a specified lock object.
PR_Unlock
unlocks a specified lock object.
#include <prlock.h>
PRLock* PR_NewLock(void);
If unsuccessful (for example, the lock cannot be created because of resource
constraints), NULL
.
PR_NewLock
creates a new opaque lock
#include <prlock.h>
void PR_DestroyLock(PRLock *lock);
PR_DestroyLock
has one parameter:
lock |
A pointer to a lock object.
|
#include <prlock.h>
void PR_Lock(PRLock *lock);
PR_Lock
has one parameter:
lock |
A pointer to the lock object to be locked.
|
PR_Lock
returns, the calling thread is "in the monitor," also called "holding
the monitor's lock." Any thread that attempts to acquire the same lock blocks until
the holder of the lock exits the monitor. Acquiring the lock is not an interruptible
operation, nor is there any timeout mechanism.
#include <prlock.h>
PRStatus PR_UnLock(PRLock *lock);
PR_UnLock
has one parameter:
lock |
A pointer to the lock object to be released.
|
PR_Success
.
If unsuccessful (for example, if the caller does not own the lock), PR_FAILURE
.
Last Updated May 18, 2001