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.

137 lines
4.3 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. //
  4. // File: asncwrkq.h
  5. //
  6. // Description: Header file for CAsyncWorkQueue class. This class uses
  7. // ATQ threads to do async work.
  8. //
  9. // Author: Mike Swafford (MikeSwa)
  10. //
  11. // History:
  12. // 3/8/99 - MikeSwa Created
  13. //
  14. // Copyright (C) 1999 Microsoft Corporation
  15. //
  16. //-----------------------------------------------------------------------------
  17. #ifndef __ASNCWRKQ_H__
  18. #define __ASNCWRKQ_H__
  19. #include "aqincs.h"
  20. #include "asyncq.h"
  21. //Async work queue call back function
  22. typedef BOOL (*PASYNC_WORK_QUEUE_FN)(PVOID pvContext,
  23. DWORD dwStatus);
  24. #define ASYNC_WORK_QUEUE_SIG 'QkrW'
  25. #define ASYNC_WORK_QUEUE_SIG_FREE 'Qkr!'
  26. #define ASYNC_WORK_QUEUE_ENTRY 'EkrW'
  27. #define ASYNC_WORK_QUEUE_ENTRY_FREE 'Ekr!'
  28. //Signatures to describe how this entry was allocated
  29. #define ASYNC_WORK_QUEUE_ENTRY_ALLOC_CPOOL_SIG 'QWAP'
  30. #define ASYNC_WORK_QUEUE_ENTRY_ALLOC_HEAP_SIG 'QWAH'
  31. #define ASYNC_WORK_QUEUE_ENTRY_ALLOC_INVALID_SIG 'QWA!'
  32. typedef enum TagAsyncWorkQueueItemState
  33. {
  34. ASYNC_WORK_QUEUE_NORMAL = 0x00000001,
  35. ASYNC_WORK_QUEUE_SHUTDOWN = 0x00000002,
  36. ASYNC_WORK_QUEUE_FAILURE = 0x00000003,
  37. //Warning flag set when failure happens on enqueue thread
  38. ASYNC_WORK_QUEUE_ENQUEUE_THREAD = 0x80000001,
  39. } AsyncWorkQueueItemState;
  40. class CAsyncWorkQueue;
  41. //---[ CAsyncWorkQueueItem ]---------------------------------------------------
  42. //
  43. //
  44. // Description:
  45. // Item in async work queue
  46. //
  47. // Hungarian:
  48. // awqi, pawqi
  49. //
  50. //-----------------------------------------------------------------------------
  51. class CAsyncWorkQueueItem :
  52. public CBaseObject
  53. {
  54. public:
  55. //define special memory allocators
  56. static CPool s_CAsyncWorkQueueItemPool;
  57. static DWORD s_cCurrentHeapAllocations;
  58. static DWORD s_cTotalHeapAllocations;
  59. void * operator new (size_t size);
  60. void operator delete(void *pv, size_t size);
  61. CAsyncWorkQueueItem(PVOID pvData,
  62. PASYNC_WORK_QUEUE_FN pfnCompletion);
  63. ~CAsyncWorkQueueItem();
  64. protected:
  65. DWORD m_dwSignature;
  66. PVOID m_pvData;
  67. PASYNC_WORK_QUEUE_FN m_pfnCompletion;
  68. friend class CAsyncWorkQueue;
  69. };
  70. //---[ CAsyncWorkQueueItemAllocatorBlock ]-------------------------------------
  71. //
  72. //
  73. // Description:
  74. // Struct used as a hidden wrapper for CAsyncWorkQueueItem allocation...
  75. // used exclusively by the CAsyncWorkQueueItem new and delete operators
  76. // Hungarian:
  77. // cpawqi, pcpawqi
  78. //
  79. //-----------------------------------------------------------------------------
  80. typedef struct TagCAsyncWorkQueueItemAllocatorBlock
  81. {
  82. DWORD m_dwSignature;
  83. CAsyncWorkQueueItem m_pawqi;
  84. } CAsyncWorkQueueItemAllocatorBlock;
  85. //---[ CAsyncWorkQueue ]-------------------------------------------------------
  86. //
  87. //
  88. // Description:
  89. // Async work queue that
  90. // Hungarian:
  91. // awq, paqw
  92. //
  93. //-----------------------------------------------------------------------------
  94. class CAsyncWorkQueue
  95. {
  96. protected:
  97. DWORD m_dwSignature;
  98. DWORD m_cWorkQueueItems;
  99. DWORD m_dwStateFlags;
  100. CAsyncQueue<CAsyncWorkQueueItem *, ASYNC_QUEUE_WORK_SIG> m_asyncq;
  101. public:
  102. CAsyncWorkQueue();
  103. ~CAsyncWorkQueue();
  104. HRESULT HrInitialize(DWORD cItemsPerThread);
  105. HRESULT HrDeinitialize(CAQSvrInst *paqinst);
  106. HRESULT HrQueueWorkItem(PVOID pvData,
  107. PASYNC_WORK_QUEUE_FN pfnCompletion);
  108. DWORD cGetWorkQueueItems() {return m_cWorkQueueItems;};
  109. static BOOL fQueueCompletion(CAsyncWorkQueueItem *pawqi,
  110. PVOID pawq);
  111. static BOOL fQueueFailure(CAsyncWorkQueueItem *pawqi,
  112. PVOID pawq);
  113. static HRESULT HrShutdownWalkFn(CAsyncWorkQueueItem *paqwi,
  114. PVOID pvContext,
  115. BOOL *pfContinue,
  116. BOOL *pfDelete);
  117. };
  118. #endif //__ASNCWRKQ_H__