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.

146 lines
3.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: workman.hxx
  7. //
  8. // Contents: Manages a queue of work items and supports aborting during
  9. // shutdown.
  10. //
  11. // History: 12-23-96 srikants Created
  12. //
  13. //----------------------------------------------------------------------------
  14. #pragma once
  15. #include <worker.hxx>
  16. #include <ciintf.h>
  17. #include <refcount.hxx>
  18. const LONGLONG esigFwAsyncWorkItem = 0x4B57534E41574641i64; // "AFWANSWK"
  19. class CWorkManager;
  20. //+---------------------------------------------------------------------------
  21. //
  22. // Class: CFwAsyncWorkItem
  23. //
  24. // Purpose: A generic work item class for use in CI framework. This class
  25. // implements the common functionality for asynchronous
  26. // processing in ContentIndex framework.
  27. //
  28. // History: 2-28-96 srikants Adapted from CCiAsyncWorkItem
  29. //
  30. // Notes: This need not be an UNWINDABLE object because it is never
  31. // constructed on stack and the constructor cannot fail. It also
  32. // does not have any unwindable embedded members.
  33. //
  34. //----------------------------------------------------------------------------
  35. class CFwAsyncWorkItem : public CDoubleLink, public PWorkItem
  36. {
  37. public:
  38. CFwAsyncWorkItem( CWorkManager & workMan, CWorkQueue & workQueue );
  39. virtual ~CFwAsyncWorkItem();
  40. //
  41. // virtual methods from PWorkItem
  42. //
  43. void AddRef();
  44. void Release();
  45. //
  46. // Methods to add and remove from the work queue.
  47. //
  48. void AddToWorkQueue();
  49. void Abort();
  50. void Done();
  51. private:
  52. LONG _refCount;
  53. protected:
  54. CWorkManager & _workMan;
  55. CWorkQueue & _workQueue;
  56. BOOL _fAbort;
  57. BOOL _fOnWorkQueue;
  58. CMutexSem _mutex;
  59. };
  60. inline void CFwAsyncWorkItem::AddRef()
  61. {
  62. InterlockedIncrement(&_refCount);
  63. }
  64. inline void CFwAsyncWorkItem::Release()
  65. {
  66. if ( InterlockedDecrement(&_refCount) <= 0 )
  67. delete this;
  68. }
  69. typedef class TDoubleList<CFwAsyncWorkItem> CFwAsyncWorkList;
  70. typedef class TFwdListIter<CFwAsyncWorkItem, CFwAsyncWorkList> CFwAsyncWorkIter;
  71. //+---------------------------------------------------------------------------
  72. //
  73. // Class: CWorkManager
  74. //
  75. // Purpose: Manages asynchronous work items.
  76. //
  77. // History: 12-23-96 srikants Created
  78. //
  79. //----------------------------------------------------------------------------
  80. class CWorkManager : INHERIT_UNWIND
  81. {
  82. INLINE_UNWIND( CWorkManager )
  83. public:
  84. CWorkManager() : _fShutdown(FALSE)
  85. {
  86. END_CONSTRUCTION( CWorkManager );
  87. }
  88. ~CWorkManager();
  89. void AddRef()
  90. {
  91. _refCount.AddRef();
  92. }
  93. void Release()
  94. {
  95. _refCount.Release();
  96. }
  97. void WaitForDeath()
  98. {
  99. _refCount.Wait();
  100. }
  101. //
  102. // Asynchronous Worker thread processing.
  103. //
  104. void RemoveFromWorkList( CFwAsyncWorkItem * pItem );
  105. void AddToWorkList( CFwAsyncWorkItem * pItem );
  106. void AbortWorkItems();
  107. private:
  108. BOOL _fShutdown;
  109. CMutexSem _mutex;
  110. CFwAsyncWorkList _workList; // Asynchronous work items
  111. CRefCount _refCount; // For the worklist
  112. };