| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/kernel/TeMutex.h
Go to the documentation of this file.

    00001 /************************************************************************************
    00002 TerraLib - a library for developing GIS applications.
    00003 Copyright � 2001-2007 INPE and Tecgraf/PUC-Rio.
    00004
    00005 This code is part of the TerraLib library.
    00006 This library is free software; you can redistribute it and/or
    00007 modify it under the terms of the GNU Lesser General Public
    00008 License as published by the Free Software Foundation; either
    00009 version 2.1 of the License, or (at your option) any later version.
    00010
    00011 You should have received a copy of the GNU Lesser General Public
    00012 License along with this library.
    00013
    00014 The authors reassure the license terms regarding the warranties.
    00015 They specifically disclaim any warranties, including, but not limited to,
    00016 the implied warranties of merchantability and fitness for a particular purpose.
    00017 The library provided hereunder is on an "as is" basis, and the authors have no
    00018 obligation to provide maintenance, support, updates, enhancements, or modifications.
    00019 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
    00020 indirect, special, incidental, or consequential damages arising out of the use
    00021 of this library and its documentation.
    00022 *************************************************************************************/
    00029 #ifndef TEMUTEX_H
    00030   #define TEMUTEX_H
    00031
    00032   #include "TeAgnostic.h"
    00033   #include "TeDefines.h"
    00034
    00035   #if TePLATFORM == TePLATFORMCODE_MSWINDOWS
    00036     #include <windows.h>
    00037            #elif TePLATFORM == TePLATFORMCODE_LINUX || TePLATFORM == TePLATFORMCODE_AIX || TePLATFORM == TePLATFORMCODE_APPLE
    00038     #include <pthread.h>
    00039     #include <errno.h>
    00040   #else
    00041     #error "ERROR: Unsupported platform"
    00042   #endif
    00043
    00049   class TL_DLL TeMutex
    00050   {
    00051     public :
    00052
    00056       TeMutex();
    00057
    00061       ~TeMutex();
    00062
    00068       inline void lock()
    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       };
    00086
    00093       inline bool tryLock()
    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       };
    00121
    00125       inline void unLock()
    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       };
    00140
    00141     protected :
    00142
    00143       #if TePLATFORM == TePLATFORMCODE_MSWINDOWS
    00144
    00148         HANDLE m_access_;
    00149
    00153         SECURITY_ATTRIBUTES m_sa_;
    00154
    00155                                  #elif TePLATFORM == TePLATFORMCODE_LINUX || TePLATFORM == TePLATFORMCODE_AIX || TePLATFORM == TePLATFORMCODE_APPLE
    00156
    00157
    00161         pthread_mutex_t m_access_;
    00162
    00163       #else
    00164         #error "Unsuported plataform"
    00165       #endif
    00166
    00167     private :
    00168
    00172       TeMutex(  const TeMutex& ) {};
    00173
    00174
    00179       const TeMutex& operator=( const TeMutex& ) { return *this; };
    00180
    00181   };
    00182
    00183 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines