lock.cpp
来自「网络socket,IO,线程池」· C++ 代码 · 共 65 行
CPP
65 行
/*
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 + =
减小字号Ctrl + -
显示快捷键?