Thread2.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef __THREADBASE_H__
  2. #define __THREADBASE_H__
  3. //线程状态
  4. typedef enum _THREADSTATUS
  5. {
  6. THREADSTATUS_STOP = 0, // 停止
  7. THREADSTATUS_WAIT, // 等待
  8. THREADSTATUS_RUNNING, // 运行
  9. THREADSTATUS_EXIT, // 线程退出
  10. THREADSTATUS_END // 程序结束
  11. }THREADSTATUS;
  12. #define MAX_SEMAPHONE_NUM 20 // 最大信号量
  13. class CThreadBase
  14. {
  15. public:
  16. CThreadBase();
  17. virtual ~CThreadBase();
  18. virtual int Start();
  19. virtual void WakeUp();
  20. virtual void Exit();
  21. virtual THREADSTATUS Run() = 0;
  22. void SetSemaphoreNum(IN CONST int nNum){m_nSemaphoreNum = nNum;}
  23. THREADSTATUS GetThreadStatus(){return m_ThreadStatus;}
  24. void SetThreadStatus(IN CONST THREADSTATUS status){m_ThreadStatus = status;}
  25. HANDLE GetThreadHanle(){return m_hThread;}
  26. unsigned int GetThreadID(){return m_nThreadID;}
  27. protected:
  28. int m_nIndex;
  29. HANDLE m_hThread;
  30. unsigned int m_nThreadID;
  31. THREADSTATUS m_ThreadStatus; // 线程状态
  32. HANDLE m_hSemaphore; // 信号量
  33. int m_nSemaphoreNum; // 信号数量
  34. HANDLE m_hExit; // 退出事件
  35. };
  36. #endif //#ifndef __THREADBASE_H__