123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #ifndef __THREADPOOL_H__
- #define __THREADPOOL_H__
- #include "ListEx.h"
- #include "ThreadQueue.h"
- #include "Lock.h"
- typedef struct _SEvent* LPSEVENT;
- class CThreadBase;
- class CWorkerThread;
- class CThreadPool
- {
- friend class CWorkerThread;
- public:
- CThreadPool();
- ~CThreadPool();
- void InitThreadPool(IN CONST int nMinNum = 4);
- void TerminateAll();
- int AddEventItem(IN CONST LPSEVENT lpEvent);
- int MoveToIdleList(IN CThreadBase* pThread);
- void SetMinKeptNum(IN CONST int nNum);
- int GetMinKeptNum();
- void SetMaxKeptNum(IN CONST int nNum);
- int GetMaxKeptNum();
- int IsDeleteThread(IN CThreadBase* pThread);
- private:
- int m_nMaxThreadNum; // 最大线程数
- int m_nMinThreadNum; // 最小线程数
- int m_nCurrThreadNum; // 当前数量
- int m_nMinKeptIdleNum; // 最小空闲保持数,小于保持数需添加线程
- int m_nMaxKeptIdleNum; // 最大空闲保持数,大于保持数需减少线程
- CThreadQueue m_ThreadList; // 线程列表
- CThreadQueue m_IdleList; // 空闲
- CThreadQueue m_BusyList; // 忙碌
- CLock m_lock;
- };
- #endif //#ifndef __THREADPOOL_H__
|