55 lines
890 B
C++
55 lines
890 B
C++
#pragma once
|
|
|
|
#define autolock(cs) WZPUBLIC::CriticalSection::AutoLock lock(cs);
|
|
|
|
#include "Windows.h"
|
|
|
|
namespace WZPUBLIC
|
|
{
|
|
|
|
class CriticalSection
|
|
{
|
|
public:
|
|
CriticalSection();
|
|
virtual ~CriticalSection();
|
|
class AutoLock;
|
|
|
|
public:
|
|
|
|
//스핀 카운트를 변경한다.
|
|
DWORD SetSpinCount(DWORD dwSpinCount = 2000);
|
|
|
|
|
|
bool TryLock();
|
|
void Lock();
|
|
void UnLock();
|
|
|
|
protected:
|
|
//동기화 객체를 초기화 한다.
|
|
BOOL InitSpinCount(DWORD dwSpinCount=2000);
|
|
void Init(void);
|
|
|
|
private:
|
|
CRITICAL_SECTION m_cs;
|
|
|
|
CriticalSection(const CriticalSection &rhs);
|
|
CriticalSection &operator=(const CriticalSection &rhs);
|
|
};
|
|
|
|
|
|
class CriticalSection::AutoLock
|
|
{
|
|
public:
|
|
AutoLock(CriticalSection &crit);
|
|
~AutoLock();
|
|
|
|
private :
|
|
CriticalSection &m_cs;
|
|
|
|
// No copies do not implement
|
|
AutoLock(const AutoLock &rhs);
|
|
AutoLock &operator=(const AutoLock &rhs);
|
|
};
|
|
|
|
};
|