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

Public Member Functions | |
| MutexSGI () | |
| ~MutexSGI () | |
| vpr::ReturnStatus | acquire () const |
| Locks this mutex. | |
| vpr::ReturnStatus | acquireRead () const |
| Acquires a read lock. | |
| vpr::ReturnStatus | acquireWrite () const |
| Acquires a write lock. | |
| vpr::ReturnStatus | tryAcquire () const |
| Tries to acquire a lock on this mutex (does not block). | |
| vpr::ReturnStatus | tryAcquireRead () const |
| Tries to acquire a read lock (does not block). | |
| vpr::ReturnStatus | tryAcquireWrite () const |
| Tries to acquire a write lock (does not block). | |
| vpr::ReturnStatus | release () const |
| Releases the mutex. | |
| int | test () const |
| Tests the current lock status. | |
| void | dump (FILE *dest=stdout, const char *message="\n------ Mutex Status -----\n") const |
| Dumps the mutex debug stuff and current state. | |
Protected Member Functions | |
| void | operator= (const MutexSGI &) |
| MutexSGI (const MutexSGI &) | |
Protected Attributes | |
| ulock_t | mMutex |
Static Protected Attributes | |
| static MemPoolSGI * | mMutexPool |
| static int * | mAttachedCounter |
Used for critical section protection. This is typedef'd to vpr::Mutex.
Definition at line 64 of file MutexSGI.h.
| vpr::MutexSGI::MutexSGI | ( | ) | [inline] |
Definition at line 67 of file MutexSGI.h.
References vpr::MemPoolSGI::allocate(), errno, vpr::MemPoolSGI::getArena(), mAttachedCounter, mMutex, mMutexPool, and vprASSERT.
00067 : mMutex(NULL) 00068 { 00069 // BUG: Possible race condition here 00070 if ( mMutexPool == NULL ) 00071 { 00072 mMutexPool = new MemPoolSGI(65536, 32, 00073 "/var/tmp/memMutexPoolSGIXXXXXX"); 00074 mAttachedCounter = static_cast<int*>(mMutexPool->allocate(sizeof(int))); 00075 *mAttachedCounter = 0; 00076 } 00077 00078 // Track how many mutexes are allocated 00079 *mAttachedCounter = *mAttachedCounter + 1; 00080 // vprDEBUG << " vpr::MutexSGI::MutexSGI: mAttachedCounter: " 00081 // << *mAttachedCounter << endl << vprDEBUG_FLUSH; 00082 00083 // ----- Allocate the mutex ----- // 00084 mMutex = usnewlock(mMutexPool->getArena()); 00085 00086 if ( NULL == mMutex ) 00087 { 00088 std::cerr << "ERROR: Failed to allocate new mutex -- " 00089 << strerror(errno) << std::endl; 00090 vprASSERT(mMutex != NULL && "in vpr::MutexSGI::MutexSGI() mMutex is NULL"); 00091 } 00092 }
| vpr::MutexSGI::~MutexSGI | ( | ) | [inline] |
Definition at line 94 of file MutexSGI.h.
References vpr::MemPoolSGI::deallocate(), vpr::MemPoolSGI::getArena(), mAttachedCounter, mMutex, and mMutexPool.
00095 { 00096 // ---- Delete the mutex --- // 00097 usfreelock(mMutex, mMutexPool->getArena()); 00098 00099 // ---- Deal with the pool --- // 00100 00101 // Track how many mutexes are allocated 00102 *mAttachedCounter = *mAttachedCounter - 1; 00103 00104 // vprDEBUG << "vpr::MutexSGI::~MutexSGI: mAttachedCounter: " 00105 // << *mAttachedCounter << endl << vprDEBUG_FLUSH; 00106 00107 if ( *mAttachedCounter == 0 ) 00108 { 00109 mMutexPool->deallocate(mAttachedCounter); 00110 mAttachedCounter = NULL; 00111 delete mMutexPool; 00112 mMutexPool = NULL; 00113 } 00114 }
| vpr::MutexSGI::MutexSGI | ( | const MutexSGI & | ) | [inline, protected] |
| vpr::ReturnStatus vpr::MutexSGI::acquire | ( | ) | const [inline] |
Locks this mutex.
Definition at line 126 of file MutexSGI.h.
References vpr::ReturnStatus::Fail, mMutex, and vprASSERT.
Referenced by acquireRead(), and acquireWrite().
00127 { 00128 vprASSERT(mMutex != NULL && "in vpr::MutexSGI::aquire() mMutex is NULL"); 00129 if ( ussetlock(mMutex) == 1 ) 00130 { 00131 return vpr::ReturnStatus(); 00132 } 00133 else 00134 { 00135 return vpr::ReturnStatus(vpr::ReturnStatus::Fail); 00136 } 00137 }
| vpr::ReturnStatus vpr::MutexSGI::acquireRead | ( | ) | const [inline] |
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 }
| vpr::ReturnStatus vpr::MutexSGI::acquireWrite | ( | ) | const [inline] |
Acquires a write lock.
Definition at line 170 of file MutexSGI.h.
References acquire().
00171 { 00172 return this->acquire(); // No special "write" semaphore -- For now 00173 }
| vpr::ReturnStatus vpr::MutexSGI::tryAcquire | ( | ) | const [inline] |
Tries to acquire a lock on this mutex (does not block).
Definition at line 186 of file MutexSGI.h.
References vpr::ReturnStatus::Fail, and mMutex.
Referenced by tryAcquireRead(), and tryAcquireWrite().
00187 { 00188 // Try 100 spins. 00189 if ( uscsetlock(mMutex, 100) == 1 ) 00190 { 00191 return vpr::ReturnStatus(); 00192 } 00193 else 00194 { 00195 return vpr::ReturnStatus(vpr::ReturnStatus::Fail); 00196 } 00197 }
| vpr::ReturnStatus vpr::MutexSGI::tryAcquireRead | ( | ) | const [inline] |
Tries to acquire a read lock (does not block).
Definition at line 210 of file MutexSGI.h.
References tryAcquire().
00211 { 00212 return this->tryAcquire(); 00213 }
| vpr::ReturnStatus vpr::MutexSGI::tryAcquireWrite | ( | ) | const [inline] |
Tries to acquire a write lock (does not block).
Definition at line 226 of file MutexSGI.h.
References tryAcquire().
00227 { 00228 return this->tryAcquire(); 00229 }
| vpr::ReturnStatus vpr::MutexSGI::release | ( | ) | const [inline] |
Releases the mutex.
Definition at line 240 of file MutexSGI.h.
References vpr::ReturnStatus::Fail, and mMutex.
00241 { 00242 if ( usunsetlock(mMutex) == 0 ) 00243 { 00244 return vpr::ReturnStatus(); 00245 } 00246 else 00247 { 00248 return vpr::ReturnStatus(vpr::ReturnStatus::Fail); 00249 } 00250 }
| int vpr::MutexSGI::test | ( | ) | const [inline] |
Tests the current lock status.
Definition at line 260 of file MutexSGI.h.
References mMutex.
00261 { 00262 return ustestlock(const_cast<ulock_t>(mMutex)); 00263 }
| void vpr::MutexSGI::dump | ( | FILE * | dest = stdout, |
|
| const char * | message = "\n------ Mutex Status -----\n" | |||
| ) | const [inline] |
Dumps the mutex debug stuff and current state.
| dest | File descriptor to which the output will be written. It defaults to stderr if no descriptor is specified. | |
| message | Message printed out before the output is dumped. |
Definition at line 276 of file MutexSGI.h.
References mMutex.
00278 { 00279 usdumplock(mMutex, dest, message); 00280 }
| void vpr::MutexSGI::operator= | ( | const MutexSGI & | ) | [inline, protected] |
ulock_t vpr::MutexSGI::mMutex [protected] |
Definition at line 283 of file MutexSGI.h.
Referenced by acquire(), dump(), MutexSGI(), release(), test(), tryAcquire(), and ~MutexSGI().
vpr::MemPoolSGI * vpr::MutexSGI::mMutexPool [static, protected] |
int * vpr::MutexSGI::mAttachedCounter [static, protected] |
1.5.1