#ifndef _THREAD_MUTEX_HPP_ #define _THREAD_MUTEX_HPP_ #ifndef _COMMON_STDIO_HPP_ #include #endif #ifndef _COMMON_WINDOWS_HPP_ #include #endif #ifndef _COMMON_STRING_HPP_ #include #endif class Mutex { public: Mutex(void); Mutex(const String &mutexName,BOOL postFixup=TRUE); virtual ~Mutex(); WORD requestMutex(DWORD waitTime=INFINITE,WORD alertable=FALSE)const; WORD releaseMutex(void)const; WORD closeMutex(void); BOOL openMutex(const String &strMutexName); const String &mutexName(void)const; BOOL isOkay(void)const; private: HANDLE mhMutex; String mMutexName; }; inline Mutex::~Mutex() { closeMutex(); } inline BOOL Mutex::openMutex(const String &strMutexName) { closeMutex(); mMutexName=strMutexName; mhMutex=::OpenMutex(EVENT_ALL_ACCESS,TRUE,(LPSTR)(String&)strMutexName); return isOkay(); } inline const String &Mutex::mutexName(void)const { return mMutexName; } inline BOOL Mutex::isOkay(void)const { return mhMutex?TRUE:FALSE; } #endif