1 Star 0 Fork 2

anonymous / rtsp

forked from 飞猪饭饭 / rtsp 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
r_thread.cpp 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
greenjim301 提交于 2017-10-02 12:07 . first commit
#include "r_thread.h"
#include <stdio.h>
#include <handleapi.h>
#include <windef.h>
#include <WinBase.h>
#include "r_util.h"
unsigned WINAPI ThreadFunction( LPVOID lpParam )
{
r_thread* ctx = static_cast<r_thread*>(lpParam);
int ret = ctx->Run();
_endthreadex( 0 );
return ret;
}
r_thread::r_thread()
: m_handle(NULL)
, m_mutex(NULL)
, m_exit_flag(0)
{
}
r_thread::~r_thread()
{
if (m_handle != NULL) {
CloseHandle(m_handle);
}
if (m_mutex != NULL) {
CloseHandle(m_mutex);
}
}
int r_thread::Start()
{
m_handle =(HANDLE) _beginthreadex(NULL, 0, ThreadFunction, this, 0, NULL);
if (m_handle == NULL) {
r_log("fail to create thread\n");
return -1;
}
m_mutex = CreateMutex(NULL, FALSE, NULL);
return 0;
}
void r_thread::RLock()
{
WaitForSingleObject(m_mutex, INFINITE);
}
void r_thread::RUnlock()
{
ReleaseMutex(m_mutex);
}
int r_thread::WaitStop()
{
WaitForSingleObject(m_handle, 5000);
CloseHandle( m_handle );
m_handle = NULL;
CloseHandle( m_mutex );
m_mutex = NULL;
return 0;
}
1
https://gitee.com/jibamao/rtsp.git
git@gitee.com:jibamao/rtsp.git
jibamao
rtsp
rtsp
master

搜索帮助