?? 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 + -