1 // Copyright 2014 Idol Software, Inc.
3 // This file is part of Doctor Dump SDK.
5 // Doctor Dump SDK is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program 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
13 // GNU Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef _SYNCHRO_H__INCLUDE_
19 #define _SYNCHRO_H__INCLUDE_
28 Handle(HANDLE hHandle
= NULL
): m_hHandle(hHandle
) {}
29 ~Handle() { Close(); }
30 operator HANDLE() { return m_hHandle
; }
31 Handle
& operator = (HANDLE hHandle
) { Close(); m_hHandle
= hHandle
; return *this; }
32 void Close() { if (m_hHandle
!= NULL
) { CloseHandle(m_hHandle
); m_hHandle
= NULL
; } }
40 FileHandle(HANDLE hHandle
= INVALID_HANDLE_VALUE
): m_hHandle(hHandle
) {}
41 ~FileHandle() { Close(); }
42 operator HANDLE() const { return m_hHandle
; }
43 FileHandle
& operator = (HANDLE hHandle
) { Close(); m_hHandle
= hHandle
; return *this; }
44 void Close() { if (m_hHandle
!= INVALID_HANDLE_VALUE
) { CloseHandle(m_hHandle
); m_hHandle
= INVALID_HANDLE_VALUE
; } }
48 class Event
: public Handle
51 Event(LPSECURITY_ATTRIBUTES pAttr
= NULL
, bool bManual
= true, bool bState
= false, LPCTSTR pName
= NULL
)
52 : Handle( CreateEvent(pAttr
, bManual
, bState
, pName
)) {}
53 void Set() { SetEvent(m_hHandle
); }
54 void Reset() { ResetEvent(m_hHandle
); }
61 SyncLockT(SyncLockT
& lock
): m_SyncObj(lock
.m_SyncObj
) { m_SyncObj
.Lock(); }
62 SyncLockT(T
& SyncObj
): m_SyncObj(SyncObj
) { m_SyncObj
.Lock(); }
63 ~SyncLockT() { m_SyncObj
.Unlock(); }
65 SyncLockT
&operator=(const SyncLockT
& lock
);
72 CriticalSection() { InitializeCriticalSection(&m_cs
); }
73 ~CriticalSection() { DeleteCriticalSection(&m_cs
); }
74 void Lock() { EnterCriticalSection(&m_cs
); }
75 void Unlock() { LeaveCriticalSection(&m_cs
); }
77 typedef SyncLockT
<CriticalSection
> SyncLock
;
79 CRITICAL_SECTION m_cs
;