vpr::MutexNSPR Class Reference

Mutex wrapper for NSPR locks. More...

#include <vpr/Sync/Mutex.h>

List of all members.

Public Member Functions

 MutexNSPR ()
 Constructor.
 ~MutexNSPR ()
 Destructor.
vpr::ReturnStatus acquire ()
 Locks this mutex.
vpr::ReturnStatus acquireRead ()
 Acquires a read lock.
vpr::ReturnStatus acquireWrite ()
 Acquires a write lock.
vpr::ReturnStatus tryAcquire ()
 Tries to acquire a lock on this mutex (does not block).
vpr::ReturnStatus tryAcquireRead ()
 Tries to acquire a read lock (does not block).
vpr::ReturnStatus tryAcquireWrite ()
 Tries to acquire a write lock (does not block).
vpr::ReturnStatus release ()
 Releases the mutex.
int test () const
 Tests the current lock status.

Protected Member Functions

MutexNSPRoperator= (const MutexNSPR &r)
 MutexNSPR (const MutexNSPR &)

Protected Attributes

PRLock * mMutex
 Mutex variable for the class.
int mLocked
 Hack used to implement mutex testing.

Friends

class CondVarNSPR


Detailed Description

Mutex wrapper for NSPR locks.

This is typedef'd to vpr::Mutex.

Definition at line 69 of file MutexNSPR.h.


Constructor & Destructor Documentation

vpr::MutexNSPR::MutexNSPR (  )  [inline]

Constructor.

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

Definition at line 78 of file MutexNSPR.h.

References vprASSERT.

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

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

Destructor.

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

Definition at line 91 of file MutexNSPR.h.

00092    {
00093       PR_DestroyLock(mMutex);
00094    }

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

Definition at line 263 of file MutexNSPR.h.

00264    {
00265       /* Do nothing. */ ;
00266    }


Member Function Documentation

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

Locks this mutex.

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 107 of file MutexNSPR.h.

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

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

Acquires a read lock.

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 128 of file MutexNSPR.h.

00129    {
00130       return this->acquire();
00131    }

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

Acquires a write lock.

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 146 of file MutexNSPR.h.

00147    {
00148       return this->acquire();
00149    }

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

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

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 162 of file MutexNSPR.h.

References vpr::ReturnStatus::Fail.

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

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

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

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 188 of file MutexNSPR.h.

00189    {
00190       return this->tryAcquire();
00191    }

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

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

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 205 of file MutexNSPR.h.

00206    {
00207       return this->tryAcquire();
00208    }

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 220 of file MutexNSPR.h.

References vpr::ReturnStatus::Fail.

Referenced by vpr::CondVarNSPR::setMutex().

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

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

Tests the current lock status.

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 241 of file MutexNSPR.h.

Referenced by vpr::CondVarNSPR::test().

00242    {
00243       return mLocked;
00244    }

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

Definition at line 256 of file MutexNSPR.h.

References mLocked, and mMutex.

00257    {
00258       mMutex = r.mMutex;
00259       mLocked = r.mLocked;
00260       return *this;
00261    }


Friends And Related Function Documentation

friend class CondVarNSPR [friend]

Definition at line 249 of file MutexNSPR.h.


Member Data Documentation

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

Mutex variable for the class.

Definition at line 252 of file MutexNSPR.h.

Referenced by operator=().

int vpr::MutexNSPR::mLocked [protected]

Hack used to implement mutex testing.

Definition at line 253 of file MutexNSPR.h.

Referenced by operator=().


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