00001 00002 #ifndef _Q_SEMAPHORE_HH_ 00003 #define _Q_SEMAPHORE_HH_ 00004 00005 #include "QError.hh" 00006 00015 class QSemaphore 00016 { 00017 public: 00024 QSemaphore(); 00025 00034 QSemaphore(bool owner, int semId); 00035 00037 virtual ~QSemaphore(); 00038 00051 bool Init(bool owner, int semId); 00052 00061 bool Lock(bool lock); 00062 00068 bool IsLocked(bool& result); 00069 00073 bool CanLock(bool& result); 00074 00080 bool SetTimeout(long timeoutMs); 00081 00083 long GetTimeout() const { return fTimeoutMs; } 00084 00086 const QError& GetError() { return fError; } 00087 00088 private: 00090 int fSemHandle; 00092 int fSemId; 00094 long fTimeoutMs; 00096 bool fOwner; 00097 00098 QError fError; 00099 00104 union semun { 00105 int val; 00106 struct semid_ds *buf; 00107 unsigned short *array; 00108 struct seminfo *__buf; 00109 }; 00110 00111 }; 00112 #endif