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.

58 lines
1.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: U H T H R E A D . C P P
  7. //
  8. // Contents: Threading support code
  9. //
  10. // Notes:
  11. //
  12. // Author: mbend 29 Sep 2000
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "uhthread.h"
  18. #include "ncbase.h"
  19. CWorkItem::CWorkItem() : m_bDeleteOnComplete(FALSE)
  20. {
  21. }
  22. CWorkItem::~CWorkItem()
  23. {
  24. }
  25. HRESULT CWorkItem::HrStart(BOOL bDeleteOnComplete)
  26. {
  27. HRESULT hr = S_OK;
  28. m_bDeleteOnComplete = bDeleteOnComplete;
  29. if(!QueueUserWorkItem(&CWorkItem::DwThreadProc, this, GetFlags()))
  30. {
  31. hr = HrFromLastWin32Error();
  32. }
  33. TraceHr(ttidError, FAL, hr, FALSE, "CWorkItem::HrStart(%x)", this);
  34. return hr;
  35. }
  36. ULONG CWorkItem::GetFlags()
  37. {
  38. return WT_EXECUTEDEFAULT;
  39. }
  40. DWORD WINAPI CWorkItem::DwThreadProc(void * pvParam)
  41. {
  42. CWorkItem * pWorkItem = reinterpret_cast<CWorkItem*>(pvParam);
  43. DWORD dwRet = pWorkItem->DwRun();
  44. if(pWorkItem->m_bDeleteOnComplete)
  45. {
  46. delete pWorkItem;
  47. }
  48. return dwRet;
  49. }