summaryrefslogtreecommitdiffstats
path: root/source/cCriticalSection.h
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-29 15:29:26 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-29 15:29:26 +0100
commite2ad02f50ac69f3789b7e475dbce469eeec29468 (patch)
tree69ceb5f7ee9b5219ef2f7058b5c84647e212f6ee /source/cCriticalSection.h
parentnow it will compile on linux (diff)
downloadcuberite-e2ad02f50ac69f3789b7e475dbce469eeec29468.tar
cuberite-e2ad02f50ac69f3789b7e475dbce469eeec29468.tar.gz
cuberite-e2ad02f50ac69f3789b7e475dbce469eeec29468.tar.bz2
cuberite-e2ad02f50ac69f3789b7e475dbce469eeec29468.tar.lz
cuberite-e2ad02f50ac69f3789b7e475dbce469eeec29468.tar.xz
cuberite-e2ad02f50ac69f3789b7e475dbce469eeec29468.tar.zst
cuberite-e2ad02f50ac69f3789b7e475dbce469eeec29468.zip
Diffstat (limited to '')
-rw-r--r--source/cCriticalSection.h41
1 files changed, 40 insertions, 1 deletions
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();
+} ;
+
+
+
+