| 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/TeSemaphore.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 *************************************************************************************/
    00023
    00024 #ifndef TESEMAPHORE_H
    00025   #define TESEMAPHORE_H
    00026
    00027   #include "TeDefines.h"
    00028   #include "TeAgnostic.h"
    00029   #include "TeDefines.h"
    00030
    00031   #if TePLATFORM == TePLATFORMCODE_MSWINDOWS
    00032     #include <windows.h>
    00033   #elif TePLATFORM == TePLATFORMCODE_LINUX || TePLATFORM == TePLATFORMCODE_AIX || TePLATFORM == TePLATFORMCODE_APPLE
    00034     #include <semaphore.h>
    00035   #else
    00036     #error "ERROR: Unsupported platform"
    00037   #endif
    00038
    00044   class TL_DLL TeSemaphore
    00045   {
    00046     public :
    00047
    00052       TeSemaphore( unsigned int count );
    00053
    00061       TeSemaphore( unsigned int count, const std::string& semName );
    00062
    00066       ~TeSemaphore();
    00067
    00071       inline void post()
    00072       {
    00073         #if TePLATFORM == TePLATFORMCODE_MSWINDOWS
    00074           TEAGN_TRUE_OR_THROW( ReleaseSemaphore( semHandlerPtr_, 1, 0 ),
    00075             "Error in semaphore post" );
    00076         #elif TePLATFORM == TePLATFORMCODE_LINUX || TePLATFORM == TePLATFORMCODE_AIX || TePLATFORM == TePLATFORMCODE_APPLE
    00077           TEAGN_TRUE_OR_THROW( 0 == sem_post( semHandlerPtr_ ),
    00078             "Error in semaphore post" );
    00079         #else
    00080           #error "Unsuported plataform"
    00081         #endif
    00082       };
    00083
    00091       inline void wait()
    00092       {
    00093         #if TePLATFORM == TePLATFORMCODE_MSWINDOWS
    00094           TEAGN_TRUE_OR_THROW( WAIT_OBJECT_0 == WaitForSingleObject(
    00095             semHandlerPtr_, INFINITE ), "Error waiting semaphore" );
    00096         #elif TePLATFORM == TePLATFORMCODE_LINUX || TePLATFORM == TePLATFORMCODE_AIX || TePLATFORM == TePLATFORMCODE_APPLE
    00097           TEAGN_TRUE_OR_THROW( 0 == sem_wait( semHandlerPtr_ ),
    00098             "Error in semaphore wait" );
    00099         #else
    00100           #error "Unsuported plataform"
    00101         #endif
    00102       };
    00103
    00111       bool wait( unsigned int waitingTime );
    00112
    00113     protected :
    00114
    00115       #if TePLATFORM == TePLATFORMCODE_MSWINDOWS
    00116
    00117         HANDLE semHandlerPtr_;
    00118       #elif TePLATFORM == TePLATFORMCODE_LINUX || TePLATFORM == TePLATFORMCODE_AIX || TePLATFORM == TePLATFORMCODE_APPLE
    00119
    00120         sem_t* semHandlerPtr_;
    00121       #else
    00122         #error "Unsuported plataform"
    00123       #endif
    00124
    00126       std::string semName_;
    00127
    00128     private :
    00129
    00133       TeSemaphore(  const TeSemaphore& ) {};
    00134
    00139       const TeSemaphore& operator=( const TeSemaphore& ) { return *this; };
    00140
    00141   };
    00142
    00143 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines