Skip to content

Instantly share code, notes, and snippets.

@RklAlx
Created September 27, 2013 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RklAlx/6727623 to your computer and use it in GitHub Desktop.
Save RklAlx/6727623 to your computer and use it in GitHub Desktop.
Critical Section
#include "Sync.h"
Sync::Sync()
{
InitializeCriticalSection(&m_cs);
}
Sync::~Sync()
{
DeleteCriticalSection(&m_cs);
}
void Sync::Lock()
{
EnterCriticalSection(&m_cs);
}
bool Sync::TryLock()
{
if(TryEnterCriticalSection(&m_cs))
return true;
return false;
}
void Sync::Unlock()
{
LeaveCriticalSection(&m_cs);
}
class Sync
{
public:
Sync();
~Sync();
void Lock();
bool TryLock();
void Unlock();
private:
CRITICAL_SECTION m_cs;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment