Semaphore.h++
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __ccxx_Semaphore_hxx
00024 #define __ccxx_Semaphore_hxx
00025
00026 #include <commonc++/Common.h++>
00027 #include <commonc++/Lock.h++>
00028 #include <commonc++/Permissions.h++>
00029 #include <commonc++/String.h++>
00030 #include <commonc++/SystemException.h++>
00031
00032 #ifdef CCXX_OS_POSIX
00033 #include <fcntl.h>
00034 #include <semaphore.h>
00035 #endif
00036
00037 namespace ccxx {
00038
00052 class COMMONCPP_API Semaphore : public Lock
00053 {
00054 public:
00055
00066 Semaphore(const String &name, uint_t value = 1,
00067 const Permissions& perm = Permissions::USER_READ_WRITE);
00068
00072 ~Semaphore() throw();
00073
00079 void init() throw(SystemException);
00080
00088 bool wait() throw();
00089
00091 inline void lock() throw()
00092 { wait(); }
00093
00100 bool tryWait() throw();
00101
00108 bool signal() throw();
00109
00112 inline void unlock() throw()
00113 { signal(); }
00114
00116 int getValue() const throw();
00117
00119 inline String getName() const
00120 { return(_name); }
00121
00122 private:
00123
00124 String _name;
00125 uint_t _value;
00126 Permissions _perm;
00127 bool _initialized;
00128
00129 #ifdef CCXX_OS_WINDOWS
00130 HANDLE _sem;
00131 #else
00132 sem_t *_sem;
00133 #endif
00134 };
00135
00136 };
00137
00138 #endif // __ccxx_Semaphore_hxx