ThreadPoolModel.h
资源名称:1731.rar [点击查看]
上传用户:swkcbjrc
上传日期:2016-04-02
资源大小:45277k
文件大小:3k
源码类别:
游戏
开发平台:
Visual C++
- #if !defined(AFX_ThreadModel_H__E26B0614_AC3A_4C15_9A41_8F10560D79E8__INCLUDED_)
- #define AFX_ThreadModel_H__E26B0614_AC3A_4C15_9A41_8F10560D79E8__INCLUDED_
- //ThreadModel.h: interface for the CThreadModel class.
- //功能描述:该类是线程池模型类该类不能定义任何数据,所以只能从该类派生新类。
- #include "GlobThread.h"
- #include "afxwin.h"
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- typedef UINT lpCallBack (LPVOID lpParam);
- typedef void lpCallBack1 (LPVOID lpParam);
- enum
- {
- SUCCESS_THREADPOOL=1,
- ERROR_THREAOOL,//其他错误
- ERROR_ENTRANCE_FALSE,//入口参数错误
- ERROR_THREADPOOL_FULL,//线程达到最大数量
- };
- enum//线程退出的一些返回码
- {
- SUCCESS_THREAD_RETURN,
- ERROR_THREAD_RETURN,
- ERROR_GLOBPOOL_NULL,
- ERROR_LPPARAM_NULL,
- ERROR_MULTIPLEEVENT_WAIT
- };
- class CThreadPoolModel
- {
- 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:
- CThreadPoolModel();
- virtual ~CThreadPoolModel();
- 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(lpCallBack *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;//死亡事件
- };
- #endif // !defined(AFX_THREADDLG_H__E26B0614_AC3A_4C15_9A41_8F10560D79E8__INCLUDED_)