📄 myosmutex.cpp
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -