#include <CondVarNSPR.h>
Collaboration diagram for vpr::CondVarNSPR:

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... | |
Definition at line 69 of file CondVarNSPR.h.
|
|
Constructor.
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 }
|
|
|
Destructor.
Definition at line 109 of file CondVarNSPR.h.
00110 {
00111 PR_DestroyCondVar(mCondVar);
00112 }
|
|
|
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.
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 }
|
|
|
Signals another thread waiting on this condition variable.
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 }
|
|
|
Signals all threads waiting on the condition variable.
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 }
|
|
|
Acquires a lock on the mutex variable associated with the condition variable.
Definition at line 212 of file CondVarNSPR.h. Referenced by vpr::ThreadNSPR::start.
00213 {
00214 return mCondMutex->acquire();
00215 }
|
|
|
Tries to acquire a lock on the mutex variable associated with the condition variable.
Definition at line 231 of file CondVarNSPR.h.
00232 {
00233 return mCondMutex->tryAcquire();
00234 }
|
|
|
Releases the lock on the mutex variable associated with the condition variable.
Definition at line 247 of file CondVarNSPR.h. Referenced by vpr::ThreadNSPR::start.
00248 {
00249 return mCondMutex->release();
00250 }
|
|
|
Changes the condition variable mutex to be the specifiec mutex variable.
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 }
|
|
|
Test the mutex to see if it is held.
Definition at line 274 of file CondVarNSPR.h.
00275 { return mCondMutex->test(); }
|
|
|
Prints out information about the condition variable to stderr.
Definition at line 285 of file CondVarNSPR.h.
00286 {
00287 std::cerr << "------------- vpr::CondVarNSPR::Dump ---------\n"
00288 << "Not Implemented yet.\n";
00289 }
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002