1 ///////////////////////////////////////////////////////////////////////////////
2 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2016 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
20 //////////////////////////////////////////////////////////////////////////////////
26 #define WIN32_LEAN_AND_MEAN 1
30 ///////////////////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////////////////
39 * wrapper for native Win32 critical sections
44 inline CriticalSection(void)
46 InitializeCriticalSection(&m_win32criticalSection
);
49 inline ~CriticalSection(void)
51 DeleteCriticalSection(&m_win32criticalSection
);
54 inline void enter(void)
56 EnterCriticalSection(&m_win32criticalSection
);
59 inline bool tryEnter(void)
61 return TryEnterCriticalSection(&m_win32criticalSection
);
64 inline void leave(void)
66 LeaveCriticalSection(&m_win32criticalSection
);
70 CRITICAL_SECTION m_win32criticalSection
;
74 * RAII-style critical section locker
79 inline CSLocker(CriticalSection
&criticalSection
)
82 m_criticalSection(criticalSection
)
84 m_criticalSection
.enter();
88 inline ~CSLocker(void)
93 inline void forceUnlock(void)
97 m_criticalSection
.leave();
102 volatile bool m_locked
;
103 CriticalSection
&m_criticalSection
;