From 9550917a49f7046389cfdd8158061477106289bd Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 21 Jul 2012 07:30:30 +0000 Subject: controllable critical section locker git-svn-id: http://svn.miranda-ng.org/main/trunk@1088 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- include/m_system_cpp.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/include/m_system_cpp.h b/include/m_system_cpp.h index ea8098f24a..4c8656b4e2 100644 --- a/include/m_system_cpp.h +++ b/include/m_system_cpp.h @@ -51,7 +51,7 @@ public: }; /////////////////////////////////////////////////////////////////////////////// -// mir_cslock - automatic locker for the critical sections +// mir_cslock - simple locker for the critical sections class mir_cslock { @@ -62,6 +62,22 @@ public: __inline ~mir_cslock() { LeaveCriticalSection(&cs); } }; +/////////////////////////////////////////////////////////////////////////////// +// mir_cslockfull - controllable locker for the critical sections + +class mir_cslockfull +{ + CRITICAL_SECTION& cs; + bool bIsLocked; + +public: + __inline void lock() { bIsLocked = true; EnterCriticalSection(&cs); } + __inline void unlock() { bIsLocked = false; LeaveCriticalSection(&cs); } + + __inline mir_cslockfull(CRITICAL_SECTION& _cs) : cs(_cs) { lock(); } + __inline ~mir_cslockfull() { if (bIsLocked) unlock(); } +}; + /////////////////////////////////////////////////////////////////////////////// // basic class for classes that should be cleared inside new() -- cgit v1.2.3