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

Public Methods | |
| MutexSGI () | |
| ~MutexSGI () | |
| vpr::ReturnStatus | acquire () const |
| Locks this mutex. More... | |
| vpr::ReturnStatus | acquireRead () const |
| Acquires a read lock. More... | |
| vpr::ReturnStatus | acquireWrite () const |
| Acquires a write lock. More... | |
| vpr::ReturnStatus | tryAcquire () const |
| Tries to acquire a lock on this mutex (does not block). More... | |
| vpr::ReturnStatus | tryAcquireRead () const |
| Tries to acquire a read lock (does not block). More... | |
| vpr::ReturnStatus | tryAcquireWrite () const |
| Tries to acquire a write lock (does not block). More... | |
| vpr::ReturnStatus | release () const |
| Releases the mutex. More... | |
| int | test () const |
| Tests the current lock status. More... | |
| void | dump (FILE *dest=stdout, const char *message="\n------Mutex Status-----\n") const |
| Dumps the mutex debug stuff and current state. More... | |
Protected Methods | |
| void | operator= (const MutexSGI &) |
| MutexSGI (const MutexSGI &) | |
Protected Attributes | |
| ulock_t | mMutex |
Static Protected Attributes | |
| MemPoolSGI * | mMutexPool = NULL |
| int * | mAttachedCounter = NULL |
Used for critical section protection.
Definition at line 62 of file MutexSGI.h.
|
|
Definition at line 65 of file MutexSGI.h. References errno, mAttachedCounter, mMutex, mMutexPool, and vprASSERT. Referenced by MutexSGI, and operator=.
00065 : mMutex(NULL) 00066 { 00067 // BUG: Possible race condition here 00068 if ( mMutexPool == NULL ) 00069 { 00070 mMutexPool = new MemPoolSGI(65536, 32, 00071 "/var/tmp/memMutexPoolSGIXXXXXX"); 00072 mAttachedCounter = static_cast<int*>(mMutexPool->allocate(sizeof(int))); 00073 *mAttachedCounter = 0; 00074 } 00075 00076 // Track how many mutexes are allocated 00077 *mAttachedCounter = *mAttachedCounter + 1; 00078 // vprDEBUG << " vpr::MutexSGI::MutexSGI: mAttachedCounter: " 00079 // << *mAttachedCounter << endl << vprDEBUG_FLUSH; 00080 00081 // ----- Allocate the mutex ----- // 00082 mMutex = usnewlock(mMutexPool->getArena()); 00083 00084 if ( NULL == mMutex ) 00085 { 00086 std::cerr << "ERROR: Failed to allocate new mutex -- " 00087 << strerror(errno) << std::endl; 00088 vprASSERT(mMutex != NULL && "in vpr::MutexSGI::MutexSGI() mMutex is NULL"); 00089 } 00090 } |
|
|
Definition at line 92 of file MutexSGI.h. References mAttachedCounter, mMutex, and mMutexPool.
00093 {
00094 // ---- Delete the mutex --- //
00095 usfreelock(mMutex, mMutexPool->getArena());
00096
00097 // ---- Deal with the pool --- //
00098
00099 // Track how many mutexes are allocated
00100 *mAttachedCounter = *mAttachedCounter - 1;
00101
00102 // vprDEBUG << "vpr::MutexSGI::~MutexSGI: mAttachedCounter: "
00103 // << *mAttachedCounter << endl << vprDEBUG_FLUSH;
00104
00105 if ( *mAttachedCounter == 0 )
00106 {
00107 mMutexPool->deallocate(mAttachedCounter);
00108 mAttachedCounter = NULL;
00109 delete mMutexPool;
00110 mMutexPool = NULL;
00111 }
00112 }
|
|
|
Definition at line 293 of file MutexSGI.h. References MutexSGI.
00293 {;}
|
|
|
Locks this mutex.
Definition at line 125 of file MutexSGI.h. References vpr::ReturnStatus::Fail, mMutex, and vprASSERT. Referenced by acquireRead, and acquireWrite.
00126 {
00127 vprASSERT(mMutex != NULL && "in vpr::MutexSGI::aquire() mMutex is NULL");
00128 if ( ussetlock(mMutex) == 1 )
00129 {
00130 return vpr::ReturnStatus();
00131 }
00132 else
00133 {
00134 return vpr::ReturnStatus(vpr::ReturnStatus::Fail);
00135 }
00136 }
|
|
|
Acquires a read lock.
Definition at line 152 of file MutexSGI.h. References acquire.
00153 {
00154 return this->acquire(); // No special "read" semaphore -- For now
00155 }
|
|
|
Acquires a write lock.
Definition at line 171 of file MutexSGI.h. References acquire.
00172 {
00173 return this->acquire(); // No special "write" semaphore -- For now
00174 }
|
|
|
Tries to acquire a lock on this mutex (does not block).
Definition at line 188 of file MutexSGI.h. References vpr::ReturnStatus::Fail, and mMutex. Referenced by tryAcquireRead, and tryAcquireWrite.
00189 {
00190 // Try 100 spins.
00191 if ( uscsetlock(mMutex, 100) == 1 )
00192 {
00193 return vpr::ReturnStatus();
00194 }
00195 else
00196 {
00197 return vpr::ReturnStatus(vpr::ReturnStatus::Fail);
00198 }
00199 }
|
|
|
Tries to acquire a read lock (does not block).
Definition at line 213 of file MutexSGI.h. References tryAcquire.
00214 {
00215 return this->tryAcquire();
00216 }
|
|
|
Tries to acquire a write lock (does not block).
Definition at line 230 of file MutexSGI.h. References tryAcquire.
00231 {
00232 return this->tryAcquire();
00233 }
|
|
|
Releases the mutex.
Definition at line 244 of file MutexSGI.h. References vpr::ReturnStatus::Fail, and mMutex.
00245 {
00246 if ( usunsetlock(mMutex) == 0 )
00247 {
00248 return vpr::ReturnStatus();
00249 }
00250 else
00251 {
00252 return vpr::ReturnStatus(vpr::ReturnStatus::Fail);
00253 }
00254 }
|
|
|
Tests the current lock status.
Definition at line 265 of file MutexSGI.h. References mMutex.
00266 {
00267 return ustestlock(const_cast<ulock_t>(mMutex));
00268 }
|
|
||||||||||||
|
Dumps the mutex debug stuff and current state.
Definition at line 282 of file MutexSGI.h. References mMutex.
00284 {
00285 usdumplock(mMutex, dest, message);
00286 }
|
|
|
Definition at line 292 of file MutexSGI.h. References MutexSGI.
00292 {;}
|
|
|
Definition at line 289 of file MutexSGI.h. Referenced by acquire, dump, MutexSGI, release, test, tryAcquire, and ~MutexSGI. |
|
|
Definition at line 47 of file MutexSGI.cpp. |
|
|
Definition at line 48 of file MutexSGI.cpp. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002