📄 threadpoolmodel.h
字号:
//ThreadModel.h: interface for the CThreadModel class.
//功能描述:该类是线程池模型类该类不能定义任何数据,所以只能从该类派生新类。
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
enum
{
SUCCESS_THREAOOL=1,
ERROR_THREAOOL,//其他错误
ERROR_ENTRANCE_FALSE,//入口参数错误
ERROR_THREAOOL_FULL,//线程达到最大数量
};
enum//线程退出的一些返回码
{
SUCCESS_THREAD_RETURN,
ERROR_THREAD_RETURN,
ERROR_GLOBPOOL_NULL,
ERROR_LPPARAM_NULL,
ERROR_MULTIPLEEVENT_WAIT
};
const DWORD _THREADDEAD_TIMEOUT= 4*1000;// 4秒线程死亡超时
class CThreaoolModel
{
private:
void InitAll(void);
void DeleteAll(void);
//
void InitCriticalSection(void);
void DestroyCriticalSection(void);
void inline TPSetLastError(int nErrorNo)
{
::EnterCriticalSection(&m_csErrorNo);
m_nErrorNo=nErrorNo;
::LeaveCriticalSection(&m_csErrorNo);
};
public:
CThreaoolModel();
virtual ~CThreaoolModel();
void SetCriThreadCount(int nCount);
int inline GetCriThreadCount(void)
{return (int)m_nCriThreadCount;};
int GetMaxThreadCount(void)
{return (int)m_nMaxThreadCount;};
int inline GetCurAllThreadCount(void)
{return (int)m_nCurAllThreadCount;};
protected:
virtual CString ShowThreadInfo(void);
BOOL CreateNewThread(AFX_THREAROC pfnThrearoc,LPVOID pParam,
HANDLE &hNewThread,DWORD &dwThreadId);
void inline SetMaxThreadCount(int nMaxThreadCount)
{m_nMaxThreadCount=nMaxThreadCount;};
int inline GetCurWorkThreadCount(void)
{return (int)m_nCurWorkThreadCount;};
void inline SetMainWnd(HWND hMainWnd)
{m_hMainWnd=hMainWnd;};
HWND inline GetMainWnd(void)
{return m_hMainWnd;};
protected:
void IncrementCurAllThreadCount(void);
void DecrementCurAllThreadCount(void);
void SetCurAllThreadCount(int nCount);
void IncrementCurWorkThreadCount(void);
void DecrementCurWorkThreadCount(void);
void SetCurWorkThreadCount(int nCount);
void IncrementCriThreadCount(void);
void DecrementCriThreadCount(void);
int inline TPGetLastError(void)
{return (m_nErrorNo);};
private:
int m_nErrorNo;//错误号码
CRITICAL_SECTION m_csErrorNo;
LONG m_nMaxThreadCount;//允许线程最大数量
LONG m_nCurAllThreadCount;//当前存在的线程数量
LONG m_nCurWorkThreadCount;//当前工作的线程数量
LONG m_nCriThreadCount;//临界线程量
HWND m_hMainWnd;//主窗口句柄
protected:
HANDLE m_hAllDeadEvent;//死亡事件
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -