📄 lock.cpp
字号:
/*
2003 by zhy
*/
#include "stdafx.h"
#include "Lock.h"
#include <Windows.h>
#include <cassert>
using namespace std;
using namespace Synchronization;
bool CAPIMutex::IsOpen()
{
assert(m_bHaveName);
m_hmutex = OpenMutex( MUTEX_ALL_ACCESS, FALSE, m_mutexName.c_str());
return m_hmutex != NULL;
}
void CAPIMutex::SetMutexName(const char* szMutexName)
{
m_mutexName = szMutexName;
m_bHaveName = true;
}
void CAPIMutex::acquire() throw(CMutexException)
{
if(m_bHaveName)
m_hmutex = CreateMutex(NULL,TRUE,m_mutexName.c_str());
else
m_hmutex = CreateMutex(NULL,TRUE,NULL);
if(m_hmutex == NULL)
return;
// throw(GetLastError(),"CreateMutex failed");
}
void CAPIMutex::release() throw(CMutexException)
{
if(ReleaseMutex(m_hmutex) == 0)
;
// throw(GetLastError(),"ReleaseMutex failed");
}
void CCriSection::acquire() throw(CMutexException)
{
::EnterCriticalSection(&mcri_);
m_iCount++;
}
void CCriSection::release() throw(CMutexException)
{
m_iCount--;
::LeaveCriticalSection(&mcri_);
}
template <class Host>
typename ClassLevelLockable<Host>::Initializer
ClassLevelLockable<Host>::initializer_;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -