vpr::MutexSGI Class Reference

Mutex wrapper for the SGI systems. More...

#include <vpr/Sync/Mutex.h>

Collaboration diagram for vpr::MutexSGI:

Collaboration graph
[legend]
List of all members.

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 MemPoolSGImMutexPool
static int * mAttachedCounter

Detailed Description

Mutex wrapper for the SGI systems.

Used for critical section protection. This is typedef'd to vpr::Mutex.

Date:
January 20, 1997

Definition at line 64 of file MutexSGI.h.


Constructor & Destructor Documentation

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]

Definition at line 287 of file MutexSGI.h.

00287 {;}


Member Function Documentation

vpr::ReturnStatus vpr::MutexSGI::acquire (  )  const [inline]

Locks this mutex.

Postcondition:
A lock on this mutex is acquired by the caller. If a lock has already been acquired by another process/thread, the caller blocks until the mutex has been freed.
Returns:
vpr::ReturnStatus::Succeed is returned if the lock is acquired successfully. vpr::ReturnStatus::Fail is returned otherwise.

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.

Postcondition:
A lock on this mutex is acquired by the caller. If a lock has already been acquired by another process/thread, the caller blocks until the mutex has been freed.
Returns:
vpr::ReturnStatus::Succeed is returned if the read lock is acquired successfully. vpr::ReturnStatus::Fail is returned otherwise.
Note:
No special read mutex has been defined for now.

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.

Postcondition:
A lock on this mutex is acquired by the caller. If a lock has already been acquired by another process/thread, the caller blocks until the mutex has been freed.
Returns:
vpr::ReturnStatus::Succeed is returned if the write lock is acquired successfully. vpr::ReturnStatus::Fail is returned otherwise.
Note:
No special write mutex has been defined for now.

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).

Postcondition:
A lock on this mutex is acquired by the caller. If a lock has already been acquired by another process/thread, the caller returns does not wait for it to be unlocked.
Returns:
vpr::ReturnStatus::Succeed is returned if the lock is acquired. vpr::ReturnStatus::Fail is returned if another thread is holding the lock already.

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).

Postcondition:
A lock on this mutex is acquired by the caller. If a lock has already been acquired by another process/thread, the caller returns does not wait for it to be unlocked.
Returns:
vpr::ReturnStatus::Succeed is returned if the read lock is acquired. vpr::ReturnStatus::Fail is returned if another thread is holding the lock already.

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).

Postcondition:
A lock on this mutex is acquired by the caller. If a lock has already been acquired by another process/thread, the caller returns does not wait for it to be unlocked.
Returns:
vpr::ReturnStatus::Succeed is returned if the write lock is acquired. vpr::ReturnStatus::Fail is returned if another thread is holding the lock already.

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.

Precondition:
This mutex must be locked.
Postcondition:
This mutex is unlocked.
Returns:
vpr::ReturnStatus::Succeed is returned if this mutex is unlocked successfully. vpr::ReturnStatus::Fail is returned otherwise.

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.

Postcondition:
The state of this mutex is returned.
Returns:
0 is returned if this mutex is not locked. 1 is returned if it is locked.

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.

Postcondition:
All important data and debugging information related to the mutex are dumped to the specified file descriptor (or to stderr if none is given).
Parameters:
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]

Definition at line 286 of file MutexSGI.h.

00286 {;}


Member Data Documentation

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]

Definition at line 289 of file MutexSGI.h.

Referenced by MutexSGI(), and ~MutexSGI().

int * vpr::MutexSGI::mAttachedCounter [static, protected]

Definition at line 290 of file MutexSGI.h.

Referenced by MutexSGI(), and ~MutexSGI().


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:55:46 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1