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.

68 lines
2.8 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: Thread.h
  3. //
  4. // Copyright (c) 1999-2000, Microsoft Corporation
  5. //
  6. // Base class that implements thread functionality. Subclass this class and
  7. // implement the virtual ThreadEntry function. When you instantiate this
  8. // class a thread gets created which will call ThreadEntry and when that
  9. // function exits will call ThreadExit. These objects should be created using
  10. // operator new because the default implementation of ThreadExit does
  11. // "->Release()". You should override this function if you don't want this
  12. // behavior. The threads are also created SUSPENDED. You make any changes
  13. // that are required in the subclass' constructor. At the end of the
  14. // constructor or from the caller of operator new a "->Resume()" can be
  15. // invoked to start the thread.
  16. //
  17. // History: 1999-08-24 vtan created
  18. // 2000-02-01 vtan moved from Neptune to Whistler
  19. // --------------------------------------------------------------------------
  20. #ifndef _Thread_
  21. #define _Thread_
  22. #include "CountedObject.h"
  23. // --------------------------------------------------------------------------
  24. // CThread
  25. //
  26. // Purpose: A base class to manage threads.
  27. //
  28. // History: 1999-08-24 vtan created
  29. // 2000-02-01 vtan moved from Neptune to Whistler
  30. // --------------------------------------------------------------------------
  31. class CThread : public CCountedObject
  32. {
  33. public:
  34. CThread (DWORD stackSpace = 0, DWORD createFlags = 0, HANDLE hToken = NULL);
  35. virtual ~CThread (void);
  36. operator HANDLE (void) const;
  37. bool IsCreated (void) const;
  38. void Suspend (void) const;
  39. void Resume (void) const;
  40. NTSTATUS Terminate (void);
  41. bool IsCompleted (void) const;
  42. DWORD WaitForCompletion (DWORD dwMilliseconds) const;
  43. DWORD GetResult (void) const;
  44. int GetPriority (void) const;
  45. void SetPriority (int newPriority) const;
  46. protected:
  47. virtual DWORD Entry (void) = 0;
  48. virtual void Exit (void);
  49. NTSTATUS SetToken (HANDLE hToken);
  50. private:
  51. static DWORD WINAPI ThreadEntryProc (void *pParameter);
  52. protected:
  53. HANDLE _hThread;
  54. bool _fCompleted;
  55. };
  56. #endif /* _Thread_ */