vpr::RWMutexNSPR Class Reference

Read/write mutex implementation using NSPR read/write mutexes (PRRWLock). More...

#include <vpr/Sync/RWMutex.h>

List of all members.

Public Member Functions

 RWMutexNSPR ()
 ~RWMutexNSPR ()
vpr::ReturnStatus acquire ()
 Locks the mutex.
vpr::ReturnStatus acquireRead ()
 Acquires a read mutex.
vpr::ReturnStatus acquireWrite ()
 Acquires a write mutex.
vpr::ReturnStatus tryAcquire ()
 Tries to acquire the mutex.
vpr::ReturnStatus tryAcquireRead ()
 Tries to acquire a read mutex.
vpr::ReturnStatus tryAcquireWrite ()
 Tries to acquire a write mutex.
vpr::ReturnStatus release ()
 Releases the mutex.

Protected Member Functions

void operator= (const RWMutexNSPR &)
 RWMutexNSPR (const RWMutexNSPR &)

Protected Attributes

int numWaitingReaders
 Tests the current lock status. Number of waiting readers.
int numWaitingWriters
 Number of waiting writers.
int mRefCount
 Value is -1 if writer has the lock, else this keeps track of the number of readers holding the lock.
PRRWLock * mRwLock


Detailed Description

Read/write mutex implementation using NSPR read/write mutexes (PRRWLock).

This is typedef'd to vpr::RWMutex.

Definition at line 61 of file RWMutexNSPR.h.


Constructor & Destructor Documentation

vpr::RWMutexNSPR::RWMutexNSPR (  )  [inline]

Definition at line 64 of file RWMutexNSPR.h.

00064                  : mRwLock(NULL)
00065    {
00066       // Note the second argument "VPR RW Mutex" is for debug purposes only
00067       mRwLock = PR_NewRWLock(0, "VPR RW Mutex");
00068    }

vpr::RWMutexNSPR::~RWMutexNSPR (  )  [inline]

Definition at line 70 of file RWMutexNSPR.h.

00071    {
00072       PR_DestroyRWLock(mRwLock);
00073    }

vpr::RWMutexNSPR::RWMutexNSPR ( const RWMutexNSPR  )  [inline, protected]

Definition at line 172 of file RWMutexNSPR.h.

00173    {
00174       /* Do nothing. */ ;
00175    }


Member Function Documentation

vpr::ReturnStatus vpr::RWMutexNSPR::acquire (  )  [inline]

Locks the mutex.

Returns:
vpr::ReturnStatus::Succeed is returned if the mutex is acquired.

vpr::ReturnStatus::Fail is returned upon error.

Definition at line 81 of file RWMutexNSPR.h.

00082    {
00083       return acquireWrite();
00084    }

vpr::ReturnStatus vpr::RWMutexNSPR::acquireRead (  )  [inline]

Acquires a read mutex.

Definition at line 89 of file RWMutexNSPR.h.

00090    {
00091       PR_RWLock_Rlock(mRwLock);
00092       return vpr::ReturnStatus();
00093    }

vpr::ReturnStatus vpr::RWMutexNSPR::acquireWrite (  )  [inline]

Acquires a write mutex.

Definition at line 98 of file RWMutexNSPR.h.

00099    {
00100       PR_RWLock_Wlock(mRwLock);
00101       return vpr::ReturnStatus();
00102    }

vpr::ReturnStatus vpr::RWMutexNSPR::tryAcquire (  )  [inline]

Tries to acquire the mutex.

Wait until the semaphore value is greater than 0. Then decrement by 1 and return. P operation.

Returns:
vpr::ReturnStatus::Succeed is returned if the mutex is acquired.

vpr::ReturnStatus::Fail is returned if the mutex is not acquired.

Definition at line 114 of file RWMutexNSPR.h.

00115    {
00116       return tryAcquireWrite();
00117    }

vpr::ReturnStatus vpr::RWMutexNSPR::tryAcquireRead (  ) 

Tries to acquire a read mutex.

Definition at line 50 of file RWMutexNSPR.cpp.

References vpr::ReturnStatus::Fail.

00051 {
00052    vpr::ReturnStatus retVal(vpr::ReturnStatus::Fail);
00053 
00054 /*
00055    if (stateLock.acquire().success())
00056    {
00057       if (mRefCount == -1 || numWaitingWriters >0)
00058       {
00059          retVal.setCode(vpr::ReturnStatus::Fail);
00060       }
00061       else
00062       {
00063          mRefCount++;
00064          retVal.setCode(vpr::ReturnStatus::Succeed);
00065       }
00066       stateLock.release();
00067    }
00068 */
00069    return retVal;
00070 }

vpr::ReturnStatus vpr::RWMutexNSPR::tryAcquireWrite (  ) 

Tries to acquire a write mutex.

Definition at line 72 of file RWMutexNSPR.cpp.

References vpr::ReturnStatus::Fail.

00073 {
00074    vpr::ReturnStatus retVal(vpr::ReturnStatus::Fail);
00075 
00076 /*
00077    if (stateLock.acquire().success())
00078    {
00079       if ( mRefCount == 0 )
00080       {
00081          mRefCount = -1;
00082          retVal.setCode(vpr::ReturnStatus::Succeed);
00083       }
00084       stateLock.release();
00085    }
00086 */
00087 
00088    return retVal;
00089 }

vpr::ReturnStatus vpr::RWMutexNSPR::release (  )  [inline]

Releases the mutex.

Returns:
vpr::ReturnStatus::Succeed is returned on success.

vpr::ReturnStatus::Fail is returned on error.

Definition at line 135 of file RWMutexNSPR.h.

00136    {
00137       PR_RWLock_Unlock(mRwLock);
00138       return vpr::ReturnStatus();
00139    }

void vpr::RWMutexNSPR::operator= ( const RWMutexNSPR  )  [inline, protected]

Definition at line 167 of file RWMutexNSPR.h.

00168    {
00169       /* Do nothing. */ ;
00170    }


Member Data Documentation

int vpr::RWMutexNSPR::numWaitingReaders [protected]

Tests the current lock status. Number of waiting readers.

Returns:
0 is returned if this mutex is not locked.

1 is returned if this mutex is locked.

Definition at line 155 of file RWMutexNSPR.h.

int vpr::RWMutexNSPR::numWaitingWriters [protected]

Number of waiting writers.

Definition at line 156 of file RWMutexNSPR.h.

int vpr::RWMutexNSPR::mRefCount [protected]

Value is -1 if writer has the lock, else this keeps track of the number of readers holding the lock.

Definition at line 162 of file RWMutexNSPR.h.

PRRWLock* vpr::RWMutexNSPR::mRwLock [protected]

Definition at line 164 of file RWMutexNSPR.h.


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:55:28 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1