Mutex Class Reference

#include <Mutex.h>


Public Member Functions

 Mutex ()
int init ()
int init (char *name)
int tryLock (int tries=0, int waitmsecs=0)
int getLock (int procSlot, bool procAccount=true)
int releaseLock (int procSlot, bool procAccount=true)
int destroy ()

Data Fields

char name [20]


Detailed Description

Definition at line 24 of file Mutex.h.


Constructor & Destructor Documentation

Mutex::Mutex (  ) 

Definition at line 22 of file Mutex.cxx.

00023 {
00024 #if defined(sparc) || defined(i686)
00025     lock =0;
00026 #else
00027     pthread_mutexattr_t attr;
00028     pthread_mutexattr_init(&attr);
00029     pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
00030     pthread_mutex_init(&mutex_, &attr);
00031 #endif
00032 }


Member Function Documentation

int Mutex::destroy (  ) 

Definition at line 205 of file Mutex.cxx.

00206 {
00207 #if defined(sparc) || defined(i686)
00208 #else
00209     return pthread_mutex_destroy(&mutex_);
00210 #endif
00211     return 0;
00212 }

int Mutex::getLock ( int  procSlot,
bool  procAccount = true 
)

Definition at line 164 of file Mutex.cxx.

References ProcessManager::addMutex(), and tryLock().

Referenced by DatabaseManagerImpl::closeDatabase(), ProcessManager::deregisterThread(), Database::getAllocDatabaseMutex(), Database::getDatabaseMutex(), LockManager::getExclusiveLock(), UniqueID::getID(), Database::getProcessTableMutex(), LockManager::getSharedLock(), Database::getTransTableMutex(), HashIndex::insert(), LockManager::isExclusiveLocked(), TupleIterator::open(), DatabaseManagerImpl::openDatabase(), ProcessManager::registerThread(), LockManager::releaseLock(), HashIndex::remove(), and HashIndex::update().

00165 {
00166     int ret=0;
00167 #if defined(sparc) || defined(i686)
00168     ret = tryLock();
00169     //add it to the has_ of the ThreadInfo
00170     if (ret ==0 && procAccount) ProcessManager::addMutex(this, procSlot);
00171 
00172     return ret;
00173 #else
00174     ret = pthread_mutex_lock(&mutex_);
00175 #endif
00176     if (ret == 0) return 0;
00177     else
00178         return 1;
00179 }

Here is the call graph for this function:

Here is the caller graph for this function:

int Mutex::init ( char *  name  ) 

Definition at line 48 of file Mutex.cxx.

References init(), and name.

00049 {
00050     if (strlen(mname) > 19 ) return 0;
00051     init();
00052     strcpy(name, mname);
00053     return 0;
00054 
00055 }

Here is the call graph for this function:

int Mutex::init (  ) 

Definition at line 34 of file Mutex.cxx.

Referenced by init(), Database::initAllocDatabaseMutex(), Database::initDatabaseMutex(), Database::initProcessTableMutex(), Database::initTransTableMutex(), and UniqueID::UniqueID().

00035 {
00036 #if defined(sparc) || defined(i686)
00037     lock = 0;
00038 #else
00039     pthread_mutexattr_t attr;
00040     pthread_mutexattr_init(&attr);
00041     int ret = pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
00042     printf("pthread_mutexattr_setpshared Returned %d\n", ret);
00043     pthread_mutex_init(&mutex_, &attr);
00044     pthread_mutexattr_destroy(&attr);
00045 #endif
00046     return 0;
00047 }

Here is the caller graph for this function:

int Mutex::releaseLock ( int  procSlot,
bool  procAccount = true 
)

Definition at line 181 of file Mutex.cxx.

References ProcessManager::removeMutex().

Referenced by DatabaseManagerImpl::closeDatabase(), ProcessManager::deregisterThread(), LockManager::getExclusiveLock(), UniqueID::getID(), LockManager::getSharedLock(), HashIndex::insert(), LockManager::isExclusiveLocked(), TupleIterator::open(), DatabaseManagerImpl::openDatabase(), ProcessManager::registerThread(), Database::releaseAllocDatabaseMutex(), Database::releaseDatabaseMutex(), LockManager::releaseLock(), Database::releaseProcessTableMutex(), Database::releaseTransTableMutex(), HashIndex::remove(), and HashIndex::update().

00182 {
00183     int ret=0;
00184 #if defined(sparc) || defined(i686)
00185     /*int *lw = &lock;
00186     if (*lw == 0) return 0;
00187     __asm__ __volatile__("movl $0, %%eax; xchgl (%%ecx), %%eax" :
00188                       "=m" (*lw) :
00189                       "ecx" (lw) :
00190                       "eax");   
00191     */
00192     lock = 0;
00193 #else
00194     ret = pthread_mutex_unlock(&mutex_);
00195 #endif
00196     if (ret == 0 && procAccount) 
00197     {
00198         ProcessManager::removeMutex(this, procSlot);
00199         return ret;
00200     }
00201     else
00202         return 1;
00203 }

Here is the call graph for this function:

Here is the caller graph for this function:

int Mutex::tryLock ( int  tries = 0,
int  waitmsecs = 0 
)

Definition at line 131 of file Mutex.cxx.

References Conf::config, ErrLockTimeOut, Config::getMutexRetries(), Config::getMutexSecs(), Config::getMutexUSecs(), printError, and os::select().

Referenced by getLock().

00132 {
00133     int tries = 0;
00134     int ret = 0;
00135     struct timeval timeout;
00136     timeout.tv_sec = 0;
00137     timeout.tv_usec = waitmsecs;
00138     if (tryTimes == 0 && waitmsecs == 0)
00139     {
00140         timeout.tv_sec = Conf::config.getMutexSecs();
00141         timeout.tv_usec = Conf::config.getMutexUSecs();
00142         tryTimes = Conf::config.getMutexRetries();
00143     }
00144     while (tries < tryTimes)
00145     {
00146 #if defined(sparc) || defined(i686)
00147     if (TSL(&lock) == 0) 
00148     {
00149         return 0; 
00150     }
00151 #else
00152     ret = pthread_mutex_trylock(&mutex_);
00153     if (EBUSY  != ret) return 0;
00154 
00155 #endif
00156         os::select(0, 0, 0, 0, &timeout);
00157         tries++;
00158     }
00159     printError(ErrLockTimeOut, "Unable to get the mutex , tried %d times", tries);
00160     return 1;
00161 }

Here is the call graph for this function:

Here is the caller graph for this function:


Field Documentation

char Mutex::name[20]

Definition at line 33 of file Mutex.h.

Referenced by ProcessManager::addMutex(), ProcessManager::deregisterThread(), init(), releaseAllResources(), and ProcessManager::removeMutex().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 22:48:46 2008 for csql by  doxygen 1.4.7