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.

114 lines
2.0 KiB

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