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.

49 lines
1.4 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  2. //
  3. // Declaration of CWorkerThread.
  4. // Creates worker threads, calls functions on them, and optionally waits for results.
  5. //
  6. #pragma once
  7. #include "tlist.h"
  8. class CWorkerThread
  9. {
  10. public:
  11. typedef void (*FunctionPointer)(void *pvParams);
  12. CWorkerThread(
  13. bool fUsesCOM, // setting fUsesCOM means the thread will call CoInitialize
  14. bool fDeferCreation // set to true not to automatically create thread in constructor
  15. );
  16. ~CWorkerThread();
  17. HRESULT Call(FunctionPointer pfn, void *pvParams, UINT cbParams, bool fBlock); // if fBlock is true, the current thread will block until the called function returns
  18. // These can be used to dynamically create and destroy the thread.
  19. // Call fails (E_FAIL) when the thread isn't going.
  20. HRESULT Create();
  21. void Terminate(bool fWaitForThreadToExit);
  22. private:
  23. friend unsigned int __stdcall WorkerThread(LPVOID lpThreadParameter);
  24. void Main();
  25. HANDLE m_hThread;
  26. unsigned int m_uiThreadId;
  27. HANDLE m_hEvent;
  28. CRITICAL_SECTION m_CriticalSection;
  29. struct CallInfo
  30. {
  31. FunctionPointer pfn;
  32. void *pvParams;
  33. HANDLE hEventOut; // if non-null, the main thread is waiting for a signal when the function has returned
  34. };
  35. TList<CallInfo> m_Calls;
  36. bool m_fUsesCOM;
  37. HRESULT m_hrCOM; // HRESULT from initializing COM
  38. bool m_fEnd; // set to true when the script thread should stop running
  39. };