/**
@file SprtLock.cpp
@brief Sprt锁操作类,SprtLock类实现
@author cxw
@version 版本编号:1.0 日期:2013-10-28 修订者:Long 修订内容:按照《C++编码规范》修改源文件
*/
#include "stdafx.h"
#include "SprtLock.h"
SprtLock::SprtLock(void)
{
createLock = false;
InitialLock();
}
SprtLock::~SprtLock()
{
#ifdef WIN32
CloseHandle(m_hMutex);
#else
pthread_mutex_destroy(&m_lock);
#endif
}
void SprtLock::InitialLock()
{
if (!createLock)
{
#ifdef WIN32
m_hMutex = CreateMutex(NULL,FALSE,NULL);
#else
pthread_mutex_init(&m_lock,NULL);
#endif
createLock = true;
}
}
int SprtLock::Lock()
{
//return WaitForSingleObject(this->m_lock,INFINITE);
#ifdef WIN32
return WaitForSingleObject(m_hMutex,INFINITE);
#else
return pthread_mutex_lock(&m_lock);
#endif
}
int SprtLock::Unlock()
{
//return SetEvent(this->m_lock);
#ifdef WIN32
return ReleaseMutex(m_hMutex);
#else
return pthread_mutex_unlock(&m_lock);
#endif
}
//void SprtLock::InitialWaite()
//{
// this->m_wait = CreateEvent(NULL, TRUE, FALSE, NULL);
//
//}
//
//int SprtLock::WaitProc()
//{
// if (WaitForSingleObject(this->m_wait, 0) == WAIT_OBJECT_0) // 这个KillClient在主线程里创建,用于控制线程退出
// {
// return Successful
// }
// else
// {
// return Failed
// }
//}
//
//int SprtLock::UnWait()
//{
// return SetEvent(this->m_wait);
//}
在window和linux上通用的SprtLock类头实现文件
原创liulong1010 ©著作权
文章标签 C++ SprtLock.cpp 文章分类 运维
上一篇:在window和linux上通用的SprtLock类头文件
下一篇:tdafx的英文全称为:Standard Application Framework Extensions(标准应用程序框架的扩展
-
在window上打造一个顺手的开发环境:在 WSL 上升级 Ubuntu 版本
在window上打造一个顺手的开发环境:在 WSL 上升级 Ubuntu 版本
PowerShell Ubuntu 重新启动 -
在linux服务上搭建一个最简单的smb文件共享
linux服务器部署一个简单的smb共享,并且添加用户设置用户权限
linux 用户组 访问共享 -
在Linux上取得Windows上的文件
我们平时做些工作会在 Linux 上,可是还是有一些限制不得不前往 Windows ,获得一些文件,比如 Office ,虽然金山提供了 Linux
windows 服务器 密码 kernel Linux -
Openvpn在linux上的完美实现
OpenVPN的工作原理、应用及排错
Linux 虚拟网卡