vpr::CondVarNSPR Class Reference

Condition variable wrapper for NSPR condition variables. More...

#include <vpr/Sync/CondVar.h>

Collaboration diagram for vpr::CondVarNSPR:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 CondVarNSPR (MutexNSPR *mutex=NULL)
 Constructor.
 ~CondVarNSPR ()
 Destructor.
vpr::ReturnStatus wait (vpr::Interval timeToWait=vpr::Interval::NoTimeout)
 Blocks on a condition.
vpr::ReturnStatus signal ()
 Signals another thread waiting on this condition variable.
vpr::ReturnStatus broadcast ()
 Signals all threads waiting on the condition variable.
vpr::ReturnStatus acquire ()
 Acquires a lock on the mutex variable associated with the condition variable.
vpr::ReturnStatus tryAcquire ()
 Tries to acquire a lock on the mutex variable associated with the condition variable.
vpr::ReturnStatus release ()
 Releases the lock on the mutex variable associated with the condition variable.
void setMutex (MutexNSPR *mutex)
 Changes the condition variable mutex to be the specifiec mutex variable.
int test ()
 Tests the mutex to see if it is held.
void dump () const
 Prints out information about the condition variable to stderr.

Detailed Description

Condition variable wrapper for NSPR condition variables.

This is typedef'd to vpr::CondVar.

Definition at line 70 of file CondVarNSPR.h.


Constructor & Destructor Documentation

vpr::CondVarNSPR::CondVarNSPR ( MutexNSPR mutex = NULL  )  [inline]

Constructor.

Postcondition:
The condition variable is intialized, and the mutex variable associated with it is defined. These two steps must be done before any other member functions can use them.
Parameters:
mutex Pointer to a vpr::MutexNSPR variable that is used in association with the condition variable in this class (optional).

Definition at line 84 of file CondVarNSPR.h.

References vprASSERT.

00085    {
00086       // If the caller did not specify a mutex variable to use with
00087       // the condition variable, use mDefaultMutex.
00088       if ( mutex == NULL )
00089       {
00090          mCondMutex = &mDefaultMutex;
00091       }
00092       else
00093       {
00094          mCondMutex = mutex;
00095       }
00096 
00097       // Initialize the condition variable.
00098       mCondVar = PR_NewCondVar(mCondMutex->mMutex);
00099 
00100       vprASSERT(mCondVar != NULL);
00101    }

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

Destructor.

Precondition:
The condition variable is no longer in use.
Postcondition:
The condition variable is destroyed.

Definition at line 109 of file CondVarNSPR.h.

00110    {
00111       PR_DestroyCondVar(mCondVar);
00112    }


Member Function Documentation

vpr::ReturnStatus vpr::CondVarNSPR::wait ( vpr::Interval  timeToWait = vpr::Interval::NoTimeout  )  [inline]

Blocks on a condition.

The lock asociated with this condition variable must be held prior to invoking this method. When invoked, the lock on the variable is released, and the calling thread is blocked until another thread informs it that the condition has changed or until the timeout expires.

Precondition:
The mutex variable associated with the condition variable must be locked.
Postcondition:
The condition variable is locked. If it was previously locked, the caller blocks until signaled.
Returns:
vpr::ReturnStatus::Succeed is returned when the calling thread is signaled.

vpr::ReturnStatus::Fail is returned if something went wrong in blocking on the condition.

Definition at line 131 of file CondVarNSPR.h.

References vpr::ReturnStatus::Fail, vpr::NSPR_getInterval(), vpr::ReturnStatus::setCode(), vpr::ReturnStatus::success(), and vprASSERT.

Referenced by vpr::ThreadNSPR::start().

00132    {
00133       vpr::ReturnStatus status;
00134 
00135       // ASSERT:  We have been locked.
00136       if ( PR_WaitCondVar(mCondVar, NSPR_getInterval(timeToWait)) != PR_SUCCESS )
00137       {
00138          status.setCode(vpr::ReturnStatus::Fail);
00139       }
00140 
00141       // XXX: Use error status to print a message before the assertion.
00142       vprASSERT(status.success());
00143 
00144       return status;
00145    }

vpr::ReturnStatus vpr::CondVarNSPR::signal (  )  [inline]

Signals another thread waiting on this condition variable.

Precondition:
The condition variable must be locked.
Postcondition:
The condition variable is unlocked, and a signal is sent to a thread waiting on it.
Returns:
vpr::ReturnStatus::Succeed is returned when the signal is sent successfully.

vpr::ReturnStatus::Fail is returned otherwise.

Definition at line 158 of file CondVarNSPR.h.

References vpr::ReturnStatus::Fail, vpr::ReturnStatus::setCode(), vpr::ReturnStatus::success(), and vprASSERT.

00159    {
00160       vpr::ReturnStatus status;
00161 
00162       // ASSERT:  We have been locked
00163       if ( PR_NotifyCondVar(mCondVar) != PR_SUCCESS )
00164       {
00165          status.setCode(vpr::ReturnStatus::Fail);
00166       }
00167 
00168       vprASSERT(status.success());
00169 
00170       return status;
00171    }

vpr::ReturnStatus vpr::CondVarNSPR::broadcast (  )  [inline]

Signals all threads waiting on the condition variable.

Precondition:
The mutex variable associated with the condition variable should be locked.
Postcondition:
The condition variable is unlocked, and all waiting threads are signaled of this event.
Returns:
vpr::ReturnStatus::Succeed is returned if the broadcast message is sent successfully.

vpr::ReturnStatus::Fail is returned otherwise.

Definition at line 185 of file CondVarNSPR.h.

References vpr::ReturnStatus::Fail, vpr::ReturnStatus::setCode(), vpr::ReturnStatus::success(), and vprASSERT.

00186    {
00187       vpr::ReturnStatus status;
00188 
00189       // ASSERT:  We have been locked
00190       if ( PR_NotifyAllCondVar(mCondVar) != PR_SUCCESS )
00191       {
00192          status.setCode(vpr::ReturnStatus::Fail);
00193       }
00194 
00195       vprASSERT(status.success());
00196 
00197       return status;
00198    }

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

Acquires a lock on the mutex variable associated with the condition variable.

Postcondition:
A lock is acquired on the mutex variable associated with the condition variable. If a lock is acquired, the caller controls the mutex variable. If it was previously locked, the caller blocks until it is unlocked.
Returns:
vpr::ReturnStatus::Succeed is returned if the lock on this condition variable is acquired successfully.

vpr::ReturnStatus::Fail is returned otherwise.

Definition at line 213 of file CondVarNSPR.h.

Referenced by vpr::ThreadNSPR::start().

00214    {
00215       return mCondMutex->acquire();
00216    }

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

Tries to acquire a lock on the mutex variable associated with the condition variable.

Postcondition:
If the mutex variable is not already locked, the caller obtains a lock on it. If it is already locked, the routine returns immediately to the caller.
Returns:
vpr::ReturnStatus::Succeed is returned if the lock on this condition variable is acquired successfully.

vpr::ReturnStatus::Fail is returned if the lock is already held by another thread.

Definition at line 231 of file CondVarNSPR.h.

00232    {
00233       return mCondMutex->tryAcquire();
00234    }

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

Releases the lock on the mutex variable associated with the condition variable.

Postcondition:
The lock held by the caller on the mutex variable is released.
Returns:
vpr::ReturnStatus::Succeed is returned if the lock on this condition variable is released successfully.

vpr::ReturnStatus::Fail is returned otherwise.

Definition at line 246 of file CondVarNSPR.h.

Referenced by vpr::ThreadNSPR::start().

00247    {
00248       return mCondMutex->release();
00249    }

void vpr::CondVarNSPR::setMutex ( MutexNSPR mutex  )  [inline]

Changes the condition variable mutex to be the specifiec mutex variable.

Precondition:
The specified mutex variable must be initialized.
Postcondition:
The condition variable associated with the mutex variable is reset to the specified variable.
Parameters:
mutex Pointer to a vpr::MutexNSPR variable that is used in association with the condition variable in this class.
Note:
NEVER call except to initialize explicitly.

Definition at line 264 of file CondVarNSPR.h.

References vpr::MutexNSPR::release().

00265    {
00266       // NOT exactly correct, but just make sure not to leave it locked
00267       mutex->release();
00268       mCondMutex = mutex;
00269    }

int vpr::CondVarNSPR::test (  )  [inline]

Tests the mutex to see if it is held.

Definition at line 272 of file CondVarNSPR.h.

References vpr::MutexNSPR::test().

00273    {
00274       return mCondMutex->test();
00275    }

void vpr::CondVarNSPR::dump (  )  const [inline]

Prints out information about the condition variable to stderr.

Postcondition:
All important data and debugging information related to the condition variable and its mutex are dumped to stderr.

Definition at line 283 of file CondVarNSPR.h.

00284    {
00285       std::cerr << "------------- vpr::CondVarNSPR::Dump ---------\n"
00286                 << "Not Implemented yet.\n";
00287    }


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