Leaked source code of windows server 2003
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.

119 lines
3.4 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: WorkItem.cpp
  3. //
  4. // Copyright (c) 1999-2000, Microsoft Corporation
  5. //
  6. // Class that implements the handling of queuing a work item and calling the
  7. // entry point of the work item function when entered in a worker thread.
  8. //
  9. // History: 1999-11-26 vtan created
  10. // 2000-08-25 vtan moved from Neptune to Whistler
  11. // --------------------------------------------------------------------------
  12. #include "StandardHeader.h"
  13. #include "WorkItem.h"
  14. #include "StatusCode.h"
  15. // --------------------------------------------------------------------------
  16. // CWorkItem::CWorkItem
  17. //
  18. // Arguments: <none>
  19. //
  20. // Returns: <none>
  21. //
  22. // Purpose: Constructor for CWorkItem.
  23. //
  24. // History: 1999-11-26 vtan created
  25. // 2000-08-25 vtan moved from Neptune to Whistler
  26. // --------------------------------------------------------------------------
  27. CWorkItem::CWorkItem (void)
  28. {
  29. }
  30. // --------------------------------------------------------------------------
  31. // CWorkItem::~CWorkItem
  32. //
  33. // Arguments: <none>
  34. //
  35. // Returns: <none>
  36. //
  37. // Purpose: Destructor for CWorkItem.
  38. //
  39. // History: 1999-11-26 vtan created
  40. // 2000-08-25 vtan moved from Neptune to Whistler
  41. // --------------------------------------------------------------------------
  42. CWorkItem::~CWorkItem (void)
  43. {
  44. }
  45. // --------------------------------------------------------------------------
  46. // CWorkItem::Queue
  47. //
  48. // Arguments: <none>
  49. //
  50. // Returns: NTSTATUS
  51. //
  52. // Purpose: Queues the work item entry function to be executed.
  53. //
  54. // History: 1999-11-26 vtan created
  55. // 2000-08-25 vtan moved from Neptune to Whistler
  56. // --------------------------------------------------------------------------
  57. NTSTATUS CWorkItem::Queue (void)
  58. {
  59. NTSTATUS status;
  60. // Initially add a reference to this work item. If the queue succeeds
  61. // then leave the reference for WorkItemEntryProc to release. Otherwise
  62. // on failure release the reference.
  63. AddRef();
  64. if (QueueUserWorkItem(WorkItemEntryProc, this, WT_EXECUTEDEFAULT) != FALSE)
  65. {
  66. status = STATUS_SUCCESS;
  67. }
  68. else
  69. {
  70. Release();
  71. status = CStatusCode::StatusCodeOfLastError();
  72. }
  73. return(status);
  74. }
  75. // --------------------------------------------------------------------------
  76. // CWorkItem::WorkItemEntryProc
  77. //
  78. // Arguments: pParameter = Context pointer passed in when queued.
  79. //
  80. // Returns: DWORD
  81. //
  82. // Purpose: Callback entry point for queued work item. Takes the context
  83. // pointer and calls the virtual function that implements the
  84. // actual work.
  85. //
  86. // History: 1999-11-26 vtan created
  87. // 2000-08-25 vtan moved from Neptune to Whistler
  88. // --------------------------------------------------------------------------
  89. DWORD WINAPI CWorkItem::WorkItemEntryProc (void *pParameter)
  90. {
  91. CWorkItem *pWorkItem;
  92. DEBUG_TRY();
  93. pWorkItem = reinterpret_cast<CWorkItem*>(pParameter);
  94. pWorkItem->Entry();
  95. pWorkItem->Release();
  96. DEBUG_EXCEPT("Breaking in CWorkItem::WorkItemEntryProc exception handler...");
  97. return(0);
  98. }