1 /* 2 * PROJECT: ReactOS Cicero 3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) 4 * PURPOSE: Cicero mutex handling 5 * COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com> 6 */ 7 8 #pragma once 9 10 #include "cicbase.h" 11 12 class CicMutex 13 { 14 HANDLE m_hMutex; 15 BOOL m_bInit; 16 17 public: CicMutex()18 CicMutex() : m_hMutex(NULL), m_bInit(FALSE) 19 { 20 } ~CicMutex()21 ~CicMutex() 22 { 23 Uninit(); 24 } 25 Init(LPSECURITY_ATTRIBUTES lpSA,LPCTSTR pszMutexName)26 void Init(LPSECURITY_ATTRIBUTES lpSA, LPCTSTR pszMutexName) 27 { 28 m_hMutex = ::CreateMutex(lpSA, FALSE, pszMutexName); 29 m_bInit = TRUE; 30 } Uninit()31 void Uninit() 32 { 33 if (m_hMutex) 34 { 35 ::CloseHandle(m_hMutex); 36 m_hMutex = NULL; 37 } 38 m_bInit = FALSE; 39 } 40 Enter()41 BOOL Enter() 42 { 43 DWORD dwWait = ::WaitForSingleObject(m_hMutex, 5000); 44 return (dwWait == WAIT_OBJECT_0) || (dwWait == WAIT_ABANDONED); 45 } Leave()46 void Leave() 47 { 48 ::ReleaseMutex(m_hMutex); 49 } 50 }; 51