3 Star 2 Fork 5

张远浩/call_demo_server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Thread.cpp 1.54 KB
一键复制 编辑 原始数据 按行查看 历史
zhangyuanhao 提交于 2015-08-15 22:38 . [MOD] 修改实现
/*================================================================
* Copyright (C) 2014 All rights reserved.
*
* 文件名称:Thread.cpp
* 创 建 者:Zhang Yuanhao
* 邮 箱:bluefoxah@gmail.com
* 创建日期:2014年09月10日
* 描 述:
*
#include "Thread.h"
================================================================*/
#include "Thread.h"
CThread::CThread()
{
m_thread_id = 0;
}
CThread::~CThread()
{
}
#ifdef _WIN32
DWORD WINAPI CThread::StartRoutine(LPVOID arg)
#else
void* CThread::StartRoutine(void* arg)
#endif
{
CThread* pThread = (CThread*)arg;
pThread->OnThreadRun();
#ifdef _WIN32
return 0;
#else
return NULL;
#endif
}
void CThread::StartThread()
{
#ifdef _WIN32
(void)CreateThread(NULL, 0, StartRoutine, this, 0, &m_thread_id);
#else
(void)pthread_create(&m_thread_id, NULL, StartRoutine, this);
#endif
}
CEventThread::CEventThread()
{
m_bRunning = false;
}
CEventThread::~CEventThread()
{
StopThread();
}
void CEventThread::StartThread()
{
m_bRunning = true;
CThread::StartThread();
}
void CEventThread::StopThread()
{
m_bRunning = false;
}
void CEventThread::OnThreadRun()
{
while (m_bRunning)
{
OnThreadTick();
}
}
CThreadNotify::CThreadNotify()
{
pthread_mutexattr_init(&m_mutexattr);
pthread_mutexattr_settype(&m_mutexattr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&m_mutex, &m_mutexattr);
pthread_cond_init(&m_cond, NULL);
}
CThreadNotify::~CThreadNotify()
{
pthread_mutexattr_destroy(&m_mutexattr);
pthread_mutex_destroy(&m_mutex);
pthread_cond_destroy(&m_cond);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/bluefoxah/call_demo_server.git
git@gitee.com:bluefoxah/call_demo_server.git
bluefoxah
call_demo_server
call_demo_server
master

搜索帮助