Created
September 27, 2013 12:07
-
-
Save RklAlx/6727623 to your computer and use it in GitHub Desktop.
Critical Section
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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