Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Examples  

vpr::MutexNSPR Class Reference

Mutex wrapper for NSPR locks. More...

#include <MutexNSPR.h>

List of all members.

Public Methods

 MutexNSPR ()
 Constructor. More...

 ~MutexNSPR ()
 Destructor. More...

vpr::ReturnStatus acquire ()
 Locks this mutex. More...

vpr::ReturnStatus acquireRead ()
 Acquires a read lock. More...

vpr::ReturnStatus acquireWrite ()
 Acquires a write lock. More...

vpr::ReturnStatus tryAcquire ()
 Tries to acquire a lock on this mutex (does not block). More...

vpr::ReturnStatus tryAcquireRead ()
 Tries to acquire a read lock (does not block). More...

vpr::ReturnStatus tryAcquireWrite ()
 Tries to acquire a write lock (does not block). More...

vpr::ReturnStatus release ()
 Releases the mutex. More...

int test () const
 Tests the current lock status. More...


Protected Methods

MutexNSPR & operator= (const MutexNSPR &r)
 MutexNSPR (const MutexNSPR &)

Protected Attributes

PRLock * mMutex
 Mutex variable for the class. More...

int mLocked

Friends

class CondVarNSPR


Detailed Description

Mutex wrapper for NSPR locks.

Definition at line 69 of file MutexNSPR.h.


Constructor & Destructor Documentation

vpr::MutexNSPR::MutexNSPR   [inline]
 

Constructor.

Precondition:
None.
Postcondition:
This mutex is initialized for use. It must be initialized before any other member functions can do anything with it.

Definition at line 79 of file MutexNSPR.h.

References vprASSERT.

00079                : mLocked(0)
00080    {
00081       // ----- Allocate the mutex ----- //
00082       mMutex = PR_NewLock();
00083       vprASSERT(mMutex != NULL);
00084    }

vpr::MutexNSPR::~MutexNSPR   [inline]
 

Destructor.

Precondition:
No thread should be in a lock-specific function.
Postcondition:
The mutex variable is destroyed.

Definition at line 92 of file MutexNSPR.h.

00093    {
00094       PR_DestroyLock(mMutex);
00095    }

vpr::MutexNSPR::MutexNSPR const MutexNSPR &    [inline, protected]
 

Definition at line 267 of file MutexNSPR.h.

00268    {
00269       /* Do nothing. */ ;
00270    }


Member Function Documentation

vpr::ReturnStatus vpr::MutexNSPR::acquire   [inline]
 

Locks this mutex.

Precondition:
None.
Postcondition:
A lock on this mutex is acquired by the caller. If a lock has already been acquired by another process/thread, the caller blocks until the mutex has been freed.
Returns:
vpr::ReturnStatus::Succeed is returned if the lock is acquired successfully. vpr::ReturnStatus::Fail is returned otherwise.

Definition at line 108 of file MutexNSPR.h.

00109    {
00110       PR_Lock(mMutex);
00111       mLocked = 1;
00112 
00113       return vpr::ReturnStatus();
00114    }

vpr::ReturnStatus vpr::MutexNSPR::acquireRead   [inline]
 

Acquires a read lock.

Precondition:
None.
Postcondition:
A lock on this mutex is acquired by the caller. If a lock has already been acquired by another process/thread, the caller blocks until the mutex has been freed.
Returns:
vpr::ReturnStatus::Succeed is returned if the read lock is acquired successfully. vpr::ReturnStatus::Fail is returned otherwise.
Note:
No special read mutex has been defined for now.

Definition at line 130 of file MutexNSPR.h.

00131    {
00132       return this->acquire();
00133    }

vpr::ReturnStatus vpr::MutexNSPR::acquireWrite   [inline]
 

Acquires a write lock.

Precondition:
None.
Postcondition:
A lock on this mutex is acquired by the caller. If a lock has already been acquired by another process/thread, the caller blocks until the mutex has been freed.
Returns:
vpr::ReturnStatus::Succeed is returned if the write lock is acquired successfully. vpr::ReturnStatus::Fail is returned otherwise.
Note:
No special write mutex has been defined for now.

Definition at line 149 of file MutexNSPR.h.

00150    {
00151       return this->acquire();
00152    }

vpr::ReturnStatus vpr::MutexNSPR::tryAcquire   [inline]
 

Tries to acquire a lock on this mutex (does not block).

Precondition:
None.
Postcondition:
A lock on this mutex is acquired by the caller. If a lock has already been acquired by another process/thread, the caller returns does not wait for it to be unlocked.
Returns:
vpr::ReturnStatus::Succeed is returned if the lock is acquired. vpr::ReturnStatus::Fail is returned if another thread is holding the lock already.

Definition at line 166 of file MutexNSPR.h.

References vpr::ReturnStatus::Fail.

00167    {
00168       // XXX: Possible race condition exists in this function implementation
00169       if ( mLocked == 0 )
00170       {
00171          this->acquire();
00172          return vpr::ReturnStatus();
00173       }
00174       else
00175       {
00176          return vpr::ReturnStatus(vpr::ReturnStatus::Fail);
00177       }
00178    }

vpr::ReturnStatus vpr::MutexNSPR::tryAcquireRead   [inline]
 

Tries to acquire a read lock (does not block).

Precondition:
None.
Postcondition:
A lock on this mutex is acquired by the caller. If a lock has already been acquired by another process/thread, the caller returns does not wait for it to be unlocked.
Returns:
vpr::ReturnStatus::Succeed is returned if the read lock is acquired. vpr::ReturnStatus::Fail is returned if another thread is holding the lock already.

Definition at line 192 of file MutexNSPR.h.

00193    {
00194       return this->tryAcquire();
00195    }

vpr::ReturnStatus vpr::MutexNSPR::tryAcquireWrite   [inline]
 

Tries to acquire a write lock (does not block).

Precondition:
None.
Postcondition:
A lock on this mutex is acquired by the caller. If a lock has already been acquired by another process/thread, the caller returns does not wait for it to be unlocked.
Returns:
vpr::ReturnStatus::Succeed is returned if the write lock is acquired. vpr::ReturnStatus::Fail is returned if another thread is holding the lock already.

Definition at line 209 of file MutexNSPR.h.

00210    {
00211       return this->tryAcquire();
00212    }

vpr::ReturnStatus vpr::MutexNSPR::release   [inline]
 

Releases the mutex.

Precondition:
This mutex must be locked.
Postcondition:
This mutex is unlocked.
Returns:
vpr::ReturnStatus::Succeed is returned if this mutex is unlocked successfully. vpr::ReturnStatus::Fail is returned otherwise.

Definition at line 223 of file MutexNSPR.h.

References vpr::ReturnStatus::Fail.

00224    {
00225       mLocked = 0;
00226       if ( PR_Unlock(mMutex) == PR_SUCCESS )
00227       {
00228          return vpr::ReturnStatus();
00229       }
00230       else
00231       {
00232          return vpr::ReturnStatus(vpr::ReturnStatus::Fail);
00233       }
00234    }

int vpr::MutexNSPR::test   const [inline]
 

Tests the current lock status.

Precondition:
None.
Postcondition:
The state of this mutex is returned.
Returns:
0 is returned if this mutex is not locked. 1 is returned if it is locked.

Definition at line 245 of file MutexNSPR.h.

00246    {
00247       return mLocked;
00248    }

MutexNSPR& vpr::MutexNSPR::operator= const MutexNSPR &    r [inline, protected]
 

Definition at line 260 of file MutexNSPR.h.

00261    {
00262       mMutex = r.mMutex;
00263       mLocked = r.mLocked;
00264       return *this;
00265    }


Friends And Related Function Documentation

friend class CondVarNSPR [friend]
 

Definition at line 253 of file MutexNSPR.h.


Member Data Documentation

PRLock* vpr::MutexNSPR::mMutex [protected]
 

Mutex variable for the class.

Definition at line 256 of file MutexNSPR.h.

int vpr::MutexNSPR::mLocked [protected]
 

Definition at line 257 of file MutexNSPR.h.


The documentation for this class was generated from the following file:
Generated on Sun May 2 14:47:01 2004 for VR Juggler Portable Runtime by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002