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.

97 lines
2.3 KiB

7 years ago
​
​
​
​
7 years ago
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
​
​
​
​
2 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. #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. TH_PRE_INIT = 0,
  25. TH_ARMED = 1,
  26. TH_WORKING = 2,
  27. //TH_SLIPS,
  28. TH_ENDED,
  29. TH_EXIT
  30. } thredStatus;
  31. #define DEFAULT_THREAD_SLEEP_TIME 10 // msec
  32. /**
  33. * TODO: Add class description
  34. *
  35. * @author Gagua
  36. */
  37. class basicThread {
  38. private:
  39. #ifndef BTH_NO_LOGGING
  40. basicLogCollection *m_pLog;
  41. #endif
  42. #if defined( __linux__ ) || defined(WIN_PTHREAD)
  43. pthread_t m_sThreadHandler;
  44. static void *m_fThreadEntryPoint(void *);
  45. #else
  46. HANDLE m_hThreadHandle;
  47. DWORD m_dwThreadID;
  48. static DWORD WINAPI m_fThreadEntryPoint( LPVOID lpParameter );
  49. #endif
  50. protected:
  51. thredStatus m_bThreadStatus;
  52. virtual void m_fThreadProc( void );
  53. public:
  54. // Constructor
  55. basicThread();
  56. // Destructor
  57. ~basicThread();
  58. virtual bool init( void );
  59. virtual bool uninit( void );
  60. thredStatus getStatus( void ){ return m_bThreadStatus; };
  61. void setStatus( thredStatus A ){ m_bThreadStatus = A; };
  62. void waitThreadEnd( bool forced = false );
  63. void abort( void );
  64. // Copy constructor
  65. // TODO: Uncomment the copy constructor when you need it.
  66. //basicThread(const basicThread& src);
  67. // Assignment operator
  68. // TODO: Uncomment the assignment operator when you need it.
  69. //basicThread& operator=(const basicThread& src);
  70. };
  71. // Constructor implementation
  72. inline basicThread::basicThread(){
  73. #ifndef BTH_NO_LOGGING
  74. m_pLog = basicLogCollection::getInstance();
  75. #endif
  76. m_bThreadStatus = TH_PRE_INIT;
  77. };
  78. // Destructor implementation
  79. inline basicThread::~basicThread(){
  80. waitThreadEnd( true );
  81. };
  82. #endif // __BASICTHREAD_H_INCL__