57 lines
1.0 KiB
C++
57 lines
1.0 KiB
C++
#ifndef _THREAD_MUTEX_HPP_
|
|
#define _THREAD_MUTEX_HPP_
|
|
#ifndef _COMMON_STDIO_HPP_
|
|
#include <common/stdio.hpp>
|
|
#endif
|
|
#ifndef _COMMON_WINDOWS_HPP_
|
|
#include <common/windows.hpp>
|
|
#endif
|
|
#ifndef _COMMON_STRING_HPP_
|
|
#include <common/string.hpp>
|
|
#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
|