From e2ad02f50ac69f3789b7e475dbce469eeec29468 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 29 Jan 2012 14:29:26 +0000 Subject: ChunkGenerator: rewritten thread-locking using the new RAII CSLock class git-svn-id: http://mc-server.googlecode.com/svn/trunk@186 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cCriticalSection.h | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'source/cCriticalSection.h') diff --git a/source/cCriticalSection.h b/source/cCriticalSection.h index fd1d34e46..60602e821 100644 --- a/source/cCriticalSection.h +++ b/source/cCriticalSection.h @@ -13,4 +13,43 @@ private: #ifndef _WIN32 void* m_Attributes; #endif -}; \ No newline at end of file +}; + + + + +/// RAII for cCriticalSection - locks the CS on creation, unlocks on destruction +class cCSLock +{ + cCriticalSection * m_CS; + + #ifdef _DEBUG + // Unlike a cCriticalSection, this object should be used from a single thread, therefore access to m_IsLocked is not threadsafe + bool m_IsLocked; + #endif // _DEBUG + +public: + cCSLock(cCriticalSection * a_CS); + ~cCSLock(); + + // Temporarily unlock or re-lock: + void Lock(void); + void Unlock(void); +} ; + + + + + +/// Temporary RAII unlock for a cCSLock. Useful for unlock-wait-relock scenarios +class cCSUnlock +{ + cCSLock & m_Lock; +public: + cCSUnlock(cCSLock & a_Lock); + ~cCSUnlock(); +} ; + + + + -- cgit v1.2.3