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

vpr::CondVarNSPR Class Reference

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

#include <CondVarNSPR.h>

Collaboration diagram for vpr::CondVarNSPR:

Collaboration graph
[legend]
List of all members.

Public Methods

 CondVarNSPR (MutexNSPR *mutex=NULL)
 Constructor. More...

 ~CondVarNSPR ()
 Destructor. More...

vpr::ReturnStatus wait (vpr::Interval timeToWait=vpr::Interval::NoTimeout)
 Blocks on a condition. More...

vpr::ReturnStatus signal ()
 Signals another thread waiting on this condition variable. More...

vpr::ReturnStatus broadcast ()
 Signals all threads waiting on the condition variable. More...

vpr::ReturnStatus acquire ()
 Acquires a lock on the mutex variable associated with the condition variable. More...

vpr::ReturnStatus tryAcquire ()
 Tries to acquire a lock on the mutex variable associated with the condition variable. More...

vpr::ReturnStatus release ()
 Releases the lock on the mutex variable associated with the condition variable. More...

void setMutex (MutexNSPR *mutex)
 Changes the condition variable mutex to be the specifiec mutex variable. More...

int test ()
 Test the mutex to see if it is held. More...

void dump (void) const
 Prints out information about the condition variable to stderr. More...


Detailed Description

Condition variable wrapper for NSPR condition variables.

Definition at line 69 of file CondVarNSPR.h.


Constructor & Destructor Documentation

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

Constructor.

Precondition:
None.
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 130 of file CondVarNSPR.h.

References vpr::ReturnStatus::Fail, vpr::Interval::NoTimeout, vpr::NSPR_getInterval, vpr::ReturnStatus::setCode, vpr::ReturnStatus::success, and vprASSERT.

Referenced by vpr::ThreadNSPR::start.

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

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 156 of file CondVarNSPR.h.

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

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

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 183 of file CondVarNSPR.h.

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

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

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

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

Precondition:
None.
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 212 of file CondVarNSPR.h.

Referenced by vpr::ThreadNSPR::start.

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

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

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

Precondition:
None.
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.

Precondition:
None.
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 247 of file CondVarNSPR.h.

Referenced by vpr::ThreadNSPR::start.

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

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 265 of file CondVarNSPR.h.

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

int vpr::CondVarNSPR::test   [inline]
 

Test the mutex to see if it is held.

Definition at line 274 of file CondVarNSPR.h.

00275    { return mCondMutex->test(); }

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

Prints out information about the condition variable to stderr.

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

Definition at line 285 of file CondVarNSPR.h.

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


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