From 4f17362aeb80e5339c58a5d3b0fbaeb88d9e701c Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 13 Feb 2012 21:47:03 +0000 Subject: Rewritten most of the code for multithreading; still not 100%, but getting there. If this commit proves to be too problematic, we can always undo it. git-svn-id: http://mc-server.googlecode.com/svn/trunk@251 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cCriticalSection.h | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'source/cCriticalSection.h') diff --git a/source/cCriticalSection.h b/source/cCriticalSection.h index 86c196255..8faa04765 100644 --- a/source/cCriticalSection.h +++ b/source/cCriticalSection.h @@ -1,18 +1,27 @@ + #pragma once + + + + class cCriticalSection { public: - cCriticalSection(); + cCriticalSection(void); ~cCriticalSection(); - void Lock(); - void Unlock(); + void Lock(void); + void Unlock(void); + private: - void* m_CriticalSectionPtr; // Pointer to a CRITICAL_SECTION object -#ifndef _WIN32 - void* m_Attributes; -#endif + + #ifdef _WIN32 + CRITICAL_SECTION m_CriticalSection; + #else // _WIN32 + void* m_CriticalSectionPtr; // Pointer to a CRITICAL_SECTION object + void* m_Attributes; + #endif // else _WIN32 }; @@ -23,10 +32,10 @@ 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 + // In Windows, it is an error to call cCriticalSection::Unlock() multiple times if the lock is not held, + // therefore we need to check this value whether we are locked or not. bool m_IsLocked; - #endif // _DEBUG public: cCSLock(cCriticalSection * a_CS); -- cgit v1.2.3