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.

96 lines
2.3 KiB

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