#include "stdafx.h"
#include "criticalsection.h"


//************************************************************
//Critical Section
//************************************************************

//BOOL InitializeCriticalSectionAndSpinCount(
//   LPCRITICAL_SECTION lpCriticalSection,
//   DWORD dwSpinCount
// );
//int __cdecl InitializeCriticalSectionAndSpinCount(
//	struct _RTL_CRITICAL_SECTION *lpCriticalSection,
//	unsigned long dwSpingCount
//);


CriticalSection::CriticalSection(char *LockName,int SpinCount)
{
    InitializeCriticalSectionAndSpinCount(&cs,SpinCount);

    if(LockName)
        Name=strdup(LockName);
    else                            
        Name=strdup("NO NAME");
}

CriticalSection::~CriticalSection()
{
    DeleteCriticalSection(&cs);
    free(Name);
}

void CriticalSection::Lock()
{
    EnterCriticalSection(&cs);
}

void CriticalSection::Unlock()
{
    LeaveCriticalSection(&cs);
}
