summaryrefslogtreecommitdiffstats
path: root/source/cCriticalSection.h
diff options
context:
space:
mode:
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();
+} ;
+
+
+
+