You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.2 KiB

7 years ago
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
7 years ago
​
  1. #ifndef __BASICTHREAD_H_INCL__
  2. #define __BASICTHREAD_H_INCL__
  3. #ifndef __linux__
  4. #ifndef WIN_PTHREAD
  5. //#define WIN_PTHREAD
  6. #endif
  7. #endif
  8. #ifdef WIN_PTHREAD
  9. #pragma comment(lib, "pthreadVC2.lib")
  10. #endif
  11. #if defined( __linux__ ) || defined(WIN_PTHREAD)
  12. #include <pthread.h>
  13. #ifdef WIN_PTHREAD
  14. #include <Windows.h>
  15. #endif
  16. #else
  17. //#include <WinSock2.h>
  18. //#include <Windows.h>
  19. #endif
  20. //#pragma message("Debug: Test point riched 2!")
  21. #include "basicLogCollection.h"
  22. typedef enum thredStatus{
  23. TH_PRE_INIT = 0,
  24. TH_ARMED = 1,
  25. TH_WORKING = 2,
  26. TH_SLIPS = 3,
  27. TH_ENDED = 4,
  28. TH_EXIT = 5
  29. } thredStatus;
  30. #define DEFAULT_THREAD_SLEEP_TIME 10 // msec
  31. /**
  32. * TODO: Add class description
  33. *
  34. * @author Gagua
  35. */
  36. class basicThread {
  37. private:
  38. basicLogCollection *m_pLog;
  39. #if defined( __linux__ ) || defined(WIN_PTHREAD)
  40. pthread_t m_sThreadHandler;
  41. static void *m_fThreadEntryPoint(void *);
  42. #else
  43. HANDLE m_hThreadHandle;
  44. DWORD m_dwThreadID;
  45. static DWORD WINAPI m_fThreadEntryPoint( LPVOID lpParameter );
  46. #endif
  47. protected:
  48. thredStatus m_bThreadStatus;
  49. virtual void m_fThreadProc( void );
  50. public:
  51. // Constructor
  52. basicThread();
  53. // Destructor
  54. ~basicThread();
  55. virtual bool init( void );
  56. virtual bool uninit( void );
  57. thredStatus getStatus( void ){ return m_bThreadStatus; };
  58. void setStatus( thredStatus A ){ m_bThreadStatus = A; };
  59. void waitThreadEnd( bool forced = false );
  60. // Copy constructor
  61. // TODO: Uncomment the copy constructor when you need it.
  62. //basicThread(const basicThread& src);
  63. // Assignment operator
  64. // TODO: Uncomment the assignment operator when you need it.
  65. //basicThread& operator=(const basicThread& src);
  66. };
  67. // Constructor implementation
  68. inline basicThread::basicThread(){
  69. m_pLog = basicLogCollection::getInstance();
  70. m_bThreadStatus = TH_PRE_INIT;
  71. };
  72. // Destructor implementation
  73. inline basicThread::~basicThread(){
  74. waitThreadEnd( true );
  75. };
  76. #endif // __BASICTHREAD_H_INCL__