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

vpr::MutexSGI Class Reference

Mutex wrapper for the SGI systems. More...

#include <MutexSGI.h>

Collaboration diagram for vpr::MutexSGI:

Collaboration graph
[legend]
List of all members.

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

MemPoolSGImMutexPool = NULL
int * mAttachedCounter = NULL

Detailed Description

Mutex wrapper for the SGI systems.

Used for critical section protection.

Date:
1-20-1997

Definition at line 62 of file MutexSGI.h.


Constructor & Destructor Documentation

vpr::MutexSGI::MutexSGI   [inline]
 

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    }

vpr::MutexSGI::~MutexSGI   [inline]
 

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    }

vpr::MutexSGI::MutexSGI const MutexSGI &    [inline, protected]
 

Definition at line 293 of file MutexSGI.h.

References MutexSGI.

00293 {;}


Member Function Documentation

vpr::ReturnStatus vpr::MutexSGI::acquire void    const [inline]
 

Locks this mutex.

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

vpr::ReturnStatus vpr::MutexSGI::acquireRead   const [inline]
 

Acquires a read lock.

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

Precondition:
None.
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 171 of file MutexSGI.h.

References acquire.

00172    {
00173       return this->acquire();      // No special "write" semaphore -- For now
00174    }

vpr::ReturnStatus vpr::MutexSGI::tryAcquire void    const [inline]
 

Tries to acquire a lock on this mutex (does not block).

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

vpr::ReturnStatus vpr::MutexSGI::tryAcquireRead   const [inline]
 

Tries to acquire a read lock (does not block).

Precondition:
None.
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 213 of file MutexSGI.h.

References tryAcquire.

00214    {
00215       return this->tryAcquire();
00216    }

vpr::ReturnStatus vpr::MutexSGI::tryAcquireWrite   const [inline]
 

Tries to acquire a write lock (does not block).

Precondition:
None.
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 230 of file MutexSGI.h.

References tryAcquire.

00231    {
00232       return this->tryAcquire();
00233    }

vpr::ReturnStatus vpr::MutexSGI::release void    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 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    }

int vpr::MutexSGI::test   const [inline]
 

Tests the current lock status.

Precondition:
None.
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 265 of file MutexSGI.h.

References mMutex.

00266    {
00267       return ustestlock(const_cast<ulock_t>(mMutex));
00268    }

void vpr::MutexSGI::dump FILE *    dest = stdout,
const char *    message = "\n------ Mutex Status -----\n"
const [inline]
 

Dumps the mutex debug stuff and current state.

Precondition:
None.
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 282 of file MutexSGI.h.

References mMutex.

00284    {
00285       usdumplock(mMutex, dest, message);
00286    }

void vpr::MutexSGI::operator= const MutexSGI &    [inline, protected]
 

Definition at line 292 of file MutexSGI.h.

References MutexSGI.

00292 {;}


Member Data Documentation

ulock_t vpr::MutexSGI::mMutex [protected]
 

Definition at line 289 of file MutexSGI.h.

Referenced by acquire, dump, MutexSGI, release, test, tryAcquire, and ~MutexSGI.

vpr::MemPoolSGI * vpr::MutexSGI::mMutexPool = NULL [static, protected]
 

Definition at line 47 of file MutexSGI.cpp.

Referenced by MutexSGI, and ~MutexSGI.

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

Definition at line 48 of file MutexSGI.cpp.

Referenced by MutexSGI, and ~MutexSGI.


The documentation for this class was generated from the following files:
Generated on Sun May 2 14:47:09 2004 for VR Juggler Portable Runtime by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002