/**
@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);
//}

转载于:https://blog.51cto.com/tianyake/1568779

在window和linux上通用的SprtLock类头实现文件相关推荐

  1. linux系统读取excel文件是否存在,小弟我用poi读excel,在window下没有有关问题,但把程序放到linux上时,读取客户端的excel文件报错,不...

    我用poi读excel,在window下没有问题,但把程序放到linux上时,读取客户端的excel文件报错,不知道如何解决 我用poi读excel,在window下没有问题,但把程序放到linux上 ...

  2. window文件转换到linux,Window和Linux上的文件相互转换

    当前位置:我的异常网» Linux/Unix » Window和Linux上的文件相互转换 Window和Linux上的文件相互转换 www.myexceptions.net  网友分享于:2013- ...

  3. sql数据库备份默认路径_在Linux上SQL Server中更改默认数据库文件和备份路径

    sql数据库备份默认路径 In a previous article, we explored the process to change default SQL dump file location ...

  4. 如何在Linux上找到包含特定文本的所有文件?

    我正在尝试找到一种方法来扫描整个Linux系统,查找包含特定文本字符串的所有文件. 只是为了澄清,我在文件中寻找文本,而不是文件名. 当我查找如何做到这一点时,我遇到了两次这个解决方案: find / ...

  5. 【转】matlab与C/C++混合编程——在Windows/Linux上调用Matlab编译的动态库文件

    转自:matlab与C/C++混合编程--在Windows/Linux上调用Matlab编译的动态库文件_sinat_18131557的博客-CSDN博客 date version comments ...

  6. linux上使用FTP下载远程PTF远程文件

    linux上使用FTP下载远程PTF远程文件 #从FTP上下载单文件到本地 #!/bin/sh mkdir /market/datacopy/222/hanguang/scada/$(date +%Y ...

  7. Linux上搭建h2引擎加载h2文件

    问题背景   因为排查canal问题,需要打开linux上部署的canal的对应的h2.mv.db文件 查了一下,原来h2官方就有这种引擎,可以加载对应的h2文件,实际上就canal的lib目录下有对 ...

  8. Debian8 Linux上安装SSH服务器并配置sshd_config文件启用root ssh登录

    Debian Linux上安装SSH服务器 安装SSH服务器debian Linux允许我们通过ssh协议登录debian服务器.SSH是从远程位置登录debian的首选方法,因为ssh协议通过Int ...

  9. 转储sql文件_在Linux上SQL Server中更改SQL转储文件位置

    转储sql文件 In this article, we will talk about SQL Dump files and the process to change the dump direct ...

最新文章

  1. 某程序员leader吐槽自己的工作就是合并周报!撕逼扯淡!跪舔领导!月薪五万却非常焦虑!...
  2. 【PTA 天梯赛】L2-1 分而治之(结构体存边)
  3. linux上热编译react,如何使用react进行热加载
  4. 为Android Studio 项目手动下载gradle
  5. java截取utf8字符串_java中常用的字符串的截取方法
  6. html不建议翻译,[译] 可用但最不常见的 HTML5 标签
  7. 求整数数组的最小值c语言,编程实现求一个整数数组num[]中的最大值与最小值并输出结果的程序...
  8. 为什么烂软件大行其道而好软件无人问津?
  9. linux下RRDTool安装方法
  10. 设计原则Python
  11. 定能解决No instances available for provider
  12. MYSQL排序加分页报错Out of sort memory, consider increasing server sort buffer size
  13. URP实现毛玻璃效果一
  14. WordPress如何设置先登录再进入主页
  15. 新买的联想笔记本计算机选项,怎么我的计算机一开机全部都是雪花
  16. gmap mysql cachet_MySQL中binlog cache使用流程解惑
  17. 关于802.11ax
  18. 分享30个分类目录网站,seo优化首选,免费提交收录
  19. 在成长的路上,我们必须与自己坦诚相见
  20. 华丽丽的旋转彩带效果

热门文章

  1. CentOS下yum安装nginx服务
  2. 【裴蜀定理】BZOJ 1441 MIN
  3. Jmeter使用jp@gc-stepping thread group做性能测试
  4. Day9-Postfix
  5. IDC运营商如何轻松建立属于自己的数据备份服务中心
  6. Android 开源框架 ( 十六 ) 视频播放器 --- JiaoZiVideoPlayer(JieCaoVideoPlayer)
  7. 医院管理系统的新机遇
  8. 【干货】前端自学之路(持续更新)
  9. 跟锦数学2017年04月
  10. 解密jQuery事件核心 - 绑定设计(一)