TeMutex Class Reference
[Multi-programming tools.]

#include <TeMutex.h>


Detailed Description

A class to deal with critical region locking.
Author:
Emiliano F. Castejon <castejon@dpi.inpe.br>

Definition at line 49 of file TeMutex.h.


Public Member Functions

void lock ()
 TeMutex ()
bool tryLock ()
void unLock ()
 ~TeMutex ()

Private Member Functions

const TeMutexoperator= (const TeMutex &)
 operator= overload.
 TeMutex (const TeMutex &)
 Alternative constructor.

Constructor & Destructor Documentation

TeMutex::TeMutex (  ) 

Default constructor.

Definition at line 13 of file TeMutex.cpp.

References NULL, pthread_mutex_init, pthread_mutexattr_init, TEAGN_TRUE_OR_THROW, and TRUE.

00014 {
00015   #if TePLATFORM == TePLATFORMCODE_MSWINDOWS
00016   
00017     m_sa_.nLength = sizeof( m_sa_ );
00018     m_sa_.lpSecurityDescriptor = NULL;
00019     m_sa_.bInheritHandle = TRUE;
00020 
00021     m_access_ = ::CreateMutex( &m_sa_, false, 0 );
00022 
00023     TEAGN_TRUE_OR_THROW( ( m_access_ != 0 ),
00024       "Unable to create mutex object instance" )
00025   
00026   #elif TePLATFORM == TePLATFORMCODE_LINUX || TePLATFORM == TePLATFORMCODE_AIX || TePLATFORM == TePLATFORMCODE_APPLE
00027   
00028     pthread_mutexattr_t access_attr;
00029     TEAGN_TRUE_OR_THROW( ( pthread_mutexattr_init( &access_attr ) == 0 ),
00030       "Unable to init mutex attributes" );
00031 
00032     pthread_mutexattr_settype( &access_attr, PTHREAD_MUTEX_DEFAULT );
00033     TEAGN_TRUE_OR_THROW( 
00034       ( pthread_mutex_init( &m_access_, &access_attr ) == 0 ),
00035       "Unable to init mutex" )
00036   
00037   #else
00038     #error "Unsuported plataform"
00039   #endif   
00040 }

TeMutex::~TeMutex (  ) 

Default destructor.

Definition at line 43 of file TeMutex.cpp.

References pthread_mutex_destroy, and unLock().

00044 {
00045   unLock();
00046   
00047   #if TePLATFORM == TePLATFORMCODE_MSWINDOWS
00048   
00049     ::CloseHandle( m_access_ );
00050   
00051   #elif TePLATFORM == TePLATFORMCODE_LINUX || TePLATFORM == TePLATFORMCODE_AIX || TePLATFORM == TePLATFORMCODE_APPLE
00052   
00053     pthread_mutex_destroy( &m_access_ );
00054   
00055   #else
00056     #error "Unsuported plataform"
00057   #endif   
00058 }

TeMutex::TeMutex ( const TeMutex  )  [inline, private]

Definition at line 172 of file TeMutex.h.

00172 {};


Member Function Documentation

void TeMutex::lock (  )  [inline]

Lock the current object instance.

Note:
If section is already busy then the current thread will be blocked until it's ready again.

Definition at line 68 of file TeMutex.h.

References pthread_mutex_lock, and TEAGN_DEBUG_CONDITION.

Referenced by TePDIParaSegStrategy::acquireNewSegID(), TePDIMMIOMatching::bicubicResampleMatrix(), TePDIMMIOMatching::calcCCorrelationMtx(), TeMultiContainer< TeMultiContainerKeyT >::clear(), PluginsParametersContainer< PluginsParametersContainerKeyT >::clear(), TeThreadJobsManager::clearAwaitingJobs(), TeCommunicator< DataType >::connect(), TeCommunicator< DataType >::ConnectMe(), TeCommunicator< DataType >::disconnect(), TeCommunicator< DataType >::DisconnectMe(), TeGeometricTransformation::eORThreadEntry(), TeThreadJobsManager::executeJob(), TePDIOFMatching::gaussianSmoothing(), TePDIMMIOMatching::generateCorrelationFeatures(), TePDIOFMatching::generateCorrWindows(), TePDIOFMatching::generateLSSurface(), TeThreadJobsManager::getAwaitingJobsNumber(), TeConnectionPool::getConnection(), TeThreadJobsManager::getJobStatus(), TeThreadJobsManager::getRunningJobsNumber(), TePDIParallelSegmenter::groupDataThreadEntry(), TeMultiContainer< TeMultiContainerKeyT >::isStored(), jobFunction(), TePDIMMIOMatching::loadImage(), TePDICorrelationMatching::loadImage(), main(), TeMultiContainer< TeMultiContainerKeyT >::multiRetrive(), TeSharedPtr< T >::operator=(), TeMultiContainer< TeMultiContainerKeyT >::operator=(), PluginsParametersContainer< PluginsParametersContainerKeyT >::operator=(), TeCommunicator< DataType >::Receive(), TeConnectionPool::releaseConnection(), TeMultiContainer< TeMultiContainerKeyT >::remove(), TeSharedPtr< T >::reset(), TeMultiContainer< TeMultiContainerKeyT >::retrive(), PluginsParametersContainer< PluginsParametersContainerKeyT >::retrive(), TePDISAMClassifier::SegThread::run(), TePDICorrelationMatching::CorrThread::run(), TePDIParallelSegmenter::segmenterThreadEntry(), TeCommunicator< DataType >::send(), TeCommunicator< DataType >::setHostObj(), TeMultiContainer< TeMultiContainerKeyT >::store(), PluginsParametersContainer< PluginsParametersContainerKeyT >::store(), TeThreadJobsManager::threadFunction(), TePDIPIManager::Toggle(), TePDIPIManager::Update(), and TeThreadJobsManager::~TeThreadJobsManager().

00069       {
00070         #if TePLATFORM == TePLATFORMCODE_MSWINDOWS
00071         
00072           DWORD return_value = 0;
00073           return_value = ::WaitForSingleObject( m_access_, INFINITE );
00074           TEAGN_DEBUG_CONDITION( ( ( return_value == WAIT_ABANDONED ) ||
00075             ( return_value == WAIT_OBJECT_0 ) ),
00076             "Unable to get mutex lock" );
00077         
00078                                 #elif TePLATFORM == TePLATFORMCODE_LINUX || TePLATFORM == TePLATFORMCODE_AIX || TePLATFORM == TePLATFORMCODE_APPLE
00079         
00080           pthread_mutex_lock( &m_access_ );
00081         
00082         #else
00083           #error "Unsuported plataform"
00084         #endif  
00085       };      

const TeMutex& TeMutex::operator= ( const TeMutex  )  [inline, private]

Returns:
A const reference to the current instance.

Definition at line 179 of file TeMutex.h.

00179 { return *this; };

bool TeMutex::tryLock (  )  [inline]

Try to lock the current object instance.

Returns:
true if OK, false if unable to lock.
Note:
If section is busy, this method will return false without blocking the current thread.

Definition at line 93 of file TeMutex.h.

References EBUSY, and pthread_mutex_trylock.

Referenced by main().

00094       {
00095         #if TePLATFORM == TePLATFORMCODE_MSWINDOWS
00096         
00097           DWORD return_value = ::WaitForSingleObject( m_access_, 
00098             10 );
00099 
00100           if( ( return_value == WAIT_OBJECT_0 ) ||
00101             ( return_value == WAIT_ABANDONED ) ) {
00102 
00103             return true;
00104           } else {
00105             return false;
00106           }
00107         
00108                                 #elif TePLATFORM == TePLATFORMCODE_LINUX || TePLATFORM == TePLATFORMCODE_AIX || TePLATFORM == TePLATFORMCODE_APPLE
00109 
00110         
00111           if( pthread_mutex_trylock( &m_access_ ) == EBUSY ) {
00112             return false;
00113           } else {
00114             return true;
00115           }
00116         
00117         #else
00118           #error "Unsuported plataform"
00119         #endif  
00120       };      

void TeMutex::unLock (  )  [inline]

Unlock the current object instance.

Definition at line 125 of file TeMutex.h.

References pthread_mutex_unlock.

Referenced by TePDIParaSegStrategy::acquireNewSegID(), TePDIMMIOMatching::bicubicResampleMatrix(), TePDIMMIOMatching::calcCCorrelationMtx(), TeMultiContainer< TeMultiContainerKeyT >::clear(), PluginsParametersContainer< PluginsParametersContainerKeyT >::clear(), TeThreadJobsManager::clearAwaitingJobs(), TeCommunicator< DataType >::connect(), TeCommunicator< DataType >::ConnectMe(), TeCommunicator< DataType >::disconnect(), TeCommunicator< DataType >::DisconnectMe(), TeGeometricTransformation::eORThreadEntry(), TeThreadJobsManager::executeJob(), TePDIOFMatching::gaussianSmoothing(), TePDIMMIOMatching::generateCorrelationFeatures(), TePDIOFMatching::generateCorrWindows(), TePDIOFMatching::generateLSSurface(), TeThreadJobsManager::getAwaitingJobsNumber(), TeConnectionPool::getConnection(), TeThreadJobsManager::getJobStatus(), TeThreadJobsManager::getRunningJobsNumber(), TePDIParallelSegmenter::groupDataThreadEntry(), TeMultiContainer< TeMultiContainerKeyT >::isStored(), jobFunction(), TePDIMMIOMatching::loadImage(), TePDICorrelationMatching::loadImage(), main(), TeMultiContainer< TeMultiContainerKeyT >::multiRetrive(), TeSharedPtr< T >::operator=(), TeMultiContainer< TeMultiContainerKeyT >::operator=(), PluginsParametersContainer< PluginsParametersContainerKeyT >::operator=(), TeCommunicator< DataType >::Receive(), TeConnectionPool::releaseConnection(), TeMultiContainer< TeMultiContainerKeyT >::remove(), TeSharedPtr< T >::reset(), TeMultiContainer< TeMultiContainerKeyT >::retrive(), PluginsParametersContainer< PluginsParametersContainerKeyT >::retrive(), TePDISAMClassifier::SegThread::run(), TePDICorrelationMatching::CorrThread::run(), TePDIParallelSegmenter::segmenterThreadEntry(), TeCommunicator< DataType >::send(), TeCommunicator< DataType >::setHostObj(), TeMultiContainer< TeMultiContainerKeyT >::store(), PluginsParametersContainer< PluginsParametersContainerKeyT >::store(), TeThreadJobsManager::threadFunction(), TePDIPIManager::Toggle(), TePDIPIManager::Update(), ~TeMutex(), and TeThreadJobsManager::~TeThreadJobsManager().

00126       {
00127         #if TePLATFORM == TePLATFORMCODE_MSWINDOWS
00128         
00129           ::ReleaseMutex( m_access_ );
00130         
00131                                 #elif TePLATFORM == TePLATFORMCODE_LINUX || TePLATFORM == TePLATFORMCODE_AIX || TePLATFORM == TePLATFORMCODE_APPLE
00132 
00133         
00134           pthread_mutex_unlock( &m_access_ );
00135         
00136         #else
00137           #error "Unsuported plataform"
00138         #endif 
00139       };      


The documentation for this class was generated from the following files:
Generated on Sun Jul 29 04:06:52 2012 for TerraLib - Development Source by  doxygen 1.5.3