semaphore_pos.hpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Ifdefs
00010 *****************************************************************************/
00011 
00012 #ifndef ECL_IPC_SEMAPHORE_POS_HPP_
00013 #define ECL_IPC_SEMAPHORE_POS_HPP_
00014 
00015 /*****************************************************************************
00016 ** Platform Check
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 ** Ecl Functionality Defines
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 ** Includes
00038 *****************************************************************************/
00039 
00040 #include <iostream>
00041 #include <string>
00042 #include <semaphore.h>
00043 #include <fcntl.h>           /* For O_* constants */
00044 #include <ecl/exceptions/standard_exception.hpp>
00045 #include <ecl/time/duration.hpp>
00046 
00047 /*****************************************************************************
00048 ** Namespaces
00049 *****************************************************************************/
00050 
00051 namespace ecl {
00052 
00053 /*****************************************************************************
00054 ** Forward Declarations
00055 *****************************************************************************/
00056 
00057 class Semaphore;
00058 
00059 #ifdef ECL_HAS_EXCEPTIONS
00060 
00061 namespace ipc {
00062 
00063 /*****************************************************************************
00064 ** Semaphore Exceptions
00065 *****************************************************************************/
00075 ECL_LOCAL ecl::StandardException openSemaphoreException(const char* loc );
00085 ECL_LOCAL ecl::StandardException tryLockSemaphoreException(const char* loc);
00086 
00087 } // namespace ipc
00088 
00089 #endif /* ECL_HAS_EXCEPTIONS */
00090 
00091 /*****************************************************************************
00092 ** Semaphores
00093 *****************************************************************************/
00110 class ECL_PUBLIC Semaphore
00111 {
00112 public:
00113         /*********************
00114         ** C&D's
00115         **********************/
00123         Semaphore() throw(StandardException);
00136         Semaphore(const std::string& string_id) ecl_assert_throw_decl(StandardException);
00142         virtual ~Semaphore();
00143 
00144         /*********************
00145         ** Locking
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 } // namespace ecl
00198 
00199 
00200 #endif /* _POSIX_SEMAPHORES > 0 */
00201 #endif /* _POSIX_SEMAPHORES */
00202 #endif /* ECL_IS_POSIX */
00203 
00204 #endif /* ECL_IPC_SEMAPHORE_POS_HPP_ */


ecl_ipc
Author(s): Daniel Stonier
autogenerated on Mon Jul 3 2017 02:21:22