Source code of Windows XP (NT5)
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.

91 lines
1.3 KiB

  1. #pragma once
  2. //---------------------------------------------------------------------------
  3. // Handle Class
  4. //
  5. // Wrapper class for Win32 HANDLE.
  6. //---------------------------------------------------------------------------
  7. class CHandle
  8. {
  9. public:
  10. CHandle(HANDLE h = NULL) :
  11. m_Handle(h)
  12. {
  13. }
  14. ~CHandle()
  15. {
  16. if (m_Handle != NULL)
  17. {
  18. CloseHandle(m_Handle);
  19. m_Handle = NULL;
  20. }
  21. }
  22. HANDLE operator =(HANDLE h)
  23. {
  24. if (m_Handle != NULL)
  25. {
  26. CloseHandle(m_Handle);
  27. }
  28. m_Handle = h;
  29. return m_Handle;
  30. }
  31. operator HANDLE() const
  32. {
  33. return m_Handle;
  34. }
  35. protected:
  36. HANDLE m_Handle;
  37. };
  38. //---------------------------------------------------------------------------
  39. // Thread Class
  40. //
  41. // Provides methods for starting and stopping a thread.
  42. // The derived class must implement the Run method and perform all thread
  43. // activity within this method. Any wait logic must include the stop event.
  44. //---------------------------------------------------------------------------
  45. class CThread
  46. {
  47. public:
  48. virtual ~CThread();
  49. protected:
  50. CThread();
  51. HANDLE StopEvent() const
  52. {
  53. return m_hStopEvent;
  54. }
  55. void StartThread();
  56. void StopThread();
  57. virtual void Run() = 0;
  58. private:
  59. static DWORD WINAPI ThreadProc(LPVOID pvParameter);
  60. private:
  61. CHandle m_hThread;
  62. DWORD m_dwThreadId;
  63. CHandle m_hStopEvent;
  64. };