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.

90 lines
2.3 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
​
​
​
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. void abort( void );
  61. // Copy constructor
  62. // TODO: Uncomment the copy constructor when you need it.
  63. //basicThread(const basicThread& src);
  64. // Assignment operator
  65. // TODO: Uncomment the assignment operator when you need it.
  66. //basicThread& operator=(const basicThread& src);
  67. };
  68. // Constructor implementation
  69. inline basicThread::basicThread(){
  70. m_pLog = basicLogCollection::getInstance();
  71. m_bThreadStatus = TH_PRE_INIT;
  72. };
  73. // Destructor implementation
  74. inline basicThread::~basicThread(){
  75. waitThreadEnd( true );
  76. };
  77. #endif // __BASICTHREAD_H_INCL__