ThreadPool.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef __THREADPOOL_H__
  2. #define __THREADPOOL_H__
  3. #include "ListEx.h"
  4. #include "ThreadQueue.h"
  5. #include "Lock.h"
  6. typedef struct _SEvent* LPSEVENT;
  7. class CThreadBase;
  8. class CWorkerThread;
  9. class CThreadPool
  10. {
  11. friend class CWorkerThread;
  12. public:
  13. CThreadPool();
  14. ~CThreadPool();
  15. void InitThreadPool(IN CONST int nMinNum = 4);
  16. void TerminateAll();
  17. int AddEventItem(IN CONST LPSEVENT lpEvent);
  18. int MoveToIdleList(IN CThreadBase* pThread);
  19. void SetMinKeptNum(IN CONST int nNum);
  20. int GetMinKeptNum();
  21. void SetMaxKeptNum(IN CONST int nNum);
  22. int GetMaxKeptNum();
  23. int IsDeleteThread(IN CThreadBase* pThread);
  24. private:
  25. int m_nMaxThreadNum; // 最大线程数
  26. int m_nMinThreadNum; // 最小线程数
  27. int m_nCurrThreadNum; // 当前数量
  28. int m_nMinKeptIdleNum; // 最小空闲保持数,小于保持数需添加线程
  29. int m_nMaxKeptIdleNum; // 最大空闲保持数,大于保持数需减少线程
  30. CThreadQueue m_ThreadList; // 线程列表
  31. CThreadQueue m_IdleList; // 空闲
  32. CThreadQueue m_BusyList; // 忙碌
  33. CLock m_lock;
  34. };
  35. #endif //#ifndef __THREADPOOL_H__