Go to the documentation of this file.00001 
00008 
00009 
00010 
00011 
00012 #ifndef ECL_IPC_SEMAPHORE_POS_HPP_
00013 #define ECL_IPC_SEMAPHORE_POS_HPP_
00014 
00015 
00016 
00017 
00018 
00019 #include <ecl/config.hpp>
00020 #if defined(ECL_IS_POSIX)
00021 #include <unistd.h>
00022 #ifdef _POSIX_SEMAPHORES
00023 #if _POSIX_SEMAPHORES > 0
00024 
00025 
00026 
00027 
00028 
00029 #ifndef ECL_HAS_POSIX_SEMAPHORES
00030   #define ECL_HAS_POSIX_SEMAPHORES
00031 #endif
00032 #ifndef ECL_HAS_SEMAPHORES
00033   #define ECL_HAS_SEMAPHORES
00034 #endif
00035 
00036 
00037 
00038 
00039 
00040 #include <iostream>
00041 #include <string>
00042 #include <semaphore.h>
00043 #include <fcntl.h>           
00044 #include <ecl/exceptions/standard_exception.hpp>
00045 #include <ecl/time/duration.hpp>
00046 
00047 
00048 
00049 
00050 
00051 namespace ecl {
00052 
00053 
00054 
00055 
00056 
00057 class Semaphore;
00058 
00059 #ifdef ECL_HAS_EXCEPTIONS
00060 
00061 namespace ipc {
00062 
00063 
00064 
00065 
00075 ECL_LOCAL ecl::StandardException openSemaphoreException(const char* loc );
00085 ECL_LOCAL ecl::StandardException tryLockSemaphoreException(const char* loc);
00086 
00087 } 
00088 
00089 #endif 
00090 
00091 
00092 
00093 
00110 class ECL_PUBLIC Semaphore
00111 {
00112 public:
00113         
00114 
00115 
00123         Semaphore() throw(StandardException);
00136         Semaphore(const std::string& string_id) ecl_assert_throw_decl(StandardException);
00142         virtual ~Semaphore();
00143 
00144         
00145 
00146 
00152         void lock();
00158         void unlock();
00165         bool trylock();
00181         bool trylock( const Duration &timeout ) ecl_debug_throw_decl(StandardException);
00182 
00183 private:
00184         std::string name;
00185         sem_t* semaphore;
00186 
00193         int count();
00194 };
00195 
00196 
00197 } 
00198 
00199 
00200 #endif 
00201 #endif 
00202 #endif 
00203 
00204 #endif