#ifndef MY_LOCK_H
#define MY_LOCK_H
#include <map>
#include <vector>
#include <Windows.h>
//临界区
class CMyCritSection{
public:
CMyCritSection(){
::InitializeCriticalSection(&m_csCritSection);
};
virtual ~CMyCritSection(){
::DeleteCriticalSection(&m_csCritSection);
};
void Lock(){
::EnterCriticalSection(&m_csCritSection);
};
void Unlock(){
::LeaveCriticalSection(&m_csCritSection);
};
private:
CRITICAL_SECTION m_csCritSection;
};
//自动锁
class CMyAutoLock{
public:
CMyAutoLock(CMyCritSection* pCritSection){
m_pCritSection = pCritSection;
m_pCritSection->Lock();
};
virtual ~CMyAutoLock(){
m_pCritSection->Unlock();
};
private:
CMyCritSection* m_pCritSection;
};
#endif //MY_LOCK_H