myosmutex.cpp
来自「以下是研究 mysql 5.0.22 得出的结果,描述并使用标准 c++演示了使」· C++ 代码 · 共 59 行
CPP
59 行
#include "myosmutex.h"
MyOSMutex::MyOSMutex()
{
#ifdef WIN32
::InitializeCriticalSection(&fMutex);
#else
(void)pthread_mutex_init(&fMutex,0);
#endif
}
MyOSMutex::~MyOSMutex()
{
#ifdef WIN32
::DeleteCriticalSection(&fMutex);
#else
pthread_mutex_destroy(&fMutex);
#endif
}
void MyOSMutex::Lock()
{
#ifdef WIN32
::EnterCriticalSection(&fMutex);
#else
(void)pthread_mutex_lock(&fMutex);
#endif
}
void MyOSMutex::Unlock()
{
#ifdef WIN32
::LeaveCriticalSection(&fMutex);
#else
pthread_mutex_unlock(&fMutex);
#endif
}
bool MyOSMutex::TryLock()
{
/*#ifdef WIN32
// Return values of this function match our API
//#define _WIN32_WINNT 0x0500
if(::TryEnterCriticalSection(&fMutex) == 0)
{
return false;
}
#else
int theErr = pthread_mutex_trylock(&fMutex);
if(theErr != 0)
{
assert(theErr == EBUSY);
return false;
}
#endif*/
return true;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?