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.

138 lines
4.1 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. //
  4. // File: Hndlmgmr.h
  5. //
  6. // Description:
  7. // Contains descriptions of the CQueueHandleManager class
  8. //
  9. // Author: mikeswa
  10. //
  11. // Copyright (C) 2001 Microsoft Corporation
  12. //
  13. //-----------------------------------------------------------------------------
  14. #ifndef __HNDLMGMR_H__
  15. #define __HNDLMGMR_H__
  16. #define CQueueHandleManager_Sig 'rgMH'
  17. #define CQueueHandleManager_SigFree 'gMH!'
  18. //---[ CQueueHandleManager ]---------------------------------------------------
  19. //
  20. // Description:
  21. // Class that handles the details of handle management for a queue.
  22. //
  23. // Currently this is designed exclusively for the async queues, but
  24. // it should be possible to expand this to include the concept of remote
  25. // queues as well.
  26. // Hungarian:
  27. // qhmgr pqhmgr
  28. //
  29. //-----------------------------------------------------------------------------
  30. class CQueueHandleManager
  31. {
  32. private:
  33. DWORD m_dwSignature;
  34. //
  35. // State information for this particular queue instance
  36. //
  37. enum {
  38. QUEUE_STATE_UNITIALIZED = 0,
  39. QUEUE_STATE_NO_BACKLOG,
  40. QUEUE_STATE_LOW_BACKLOG,
  41. QUEUE_STATE_BACKLOG,
  42. QUEUE_STATE_ASYNC_BACKLOG,
  43. };
  44. DWORD m_dwCurrentState;
  45. //
  46. // Number of items that this instance can process concurrently
  47. // that is not part of a shared resource pool. This might be
  48. // the number of synchronous threads... or based on async
  49. // completions.
  50. //
  51. // $$REVIEW - How does this work for queues that have a
  52. // potentially large number of pending async completions
  53. // (like the precar queue). Currrently, this can eat of all
  54. // of the handler managers resources and cannot be dynamically
  55. // controlled. For now, we will ignore this problem and
  56. // only report the number of sync completions. This will matter
  57. // more when we implement async local delivery.
  58. //
  59. DWORD m_cMaxPrivateConcurrentItems;
  60. //
  61. // Max number of items that can be handles concurrently due
  62. // to a shared resource (like a thread pool)
  63. //
  64. DWORD m_cMaxSharedConcurrentItems;
  65. //
  66. // "Debug" counter that is updated in a non-thread safe
  67. // manner. Used to give an idea of the rough #of updates
  68. // and state transitions
  69. //
  70. DWORD m_cDbgStateTransitions;
  71. DWORD m_cDbgCallsToUpdateStateIfNecessary;
  72. //
  73. // Static data that is used to load balance across all
  74. // instances
  75. //
  76. static DWORD s_cNumQueueInstances;
  77. static DWORD s_cNumQueueInstancesWithLowBackLog;
  78. //
  79. // reserved so that empty queues have a better chance of
  80. // not bouncing handles.
  81. //
  82. static DWORD s_cReservedHandles;
  83. static DWORD s_cMaxSharedConcurrentItems;
  84. void DeinitializeStaticsAndStateIfNecessary();
  85. DWORD dwUpdateCurrentStateIfNeccessary(
  86. DWORD cItemsPending,
  87. DWORD cItemsPendingAsyncCompletions);
  88. //
  89. // Static function that gets state for a given set oflengths.
  90. // This is used internally to determine the correct response
  91. // for fShould CloseHandle
  92. //
  93. static DWORD dwGetStateForLengths(
  94. DWORD cItemsPending,
  95. DWORD cItemsPendingAsyncCompletions);
  96. //
  97. // static function that can be used to get an effective handle
  98. // limit given the state. This is used internally to determine
  99. // the correct response for fShould CloseHandle
  100. //
  101. static DWORD cGetHandleLimitForState(DWORD dwState);
  102. public:
  103. CQueueHandleManager();
  104. ~CQueueHandleManager();
  105. BOOL fIsInitialized()
  106. {return (QUEUE_STATE_UNITIALIZED != m_dwCurrentState);};
  107. //
  108. // Each instance should call into this before using any of
  109. //
  110. void SetMaxConcurrentItems(
  111. DWORD cMaxSharedConcurrentItems, //ie - async threads pool limit
  112. DWORD cMaxPrivateConcurrentItems); //ie - sync threads limit
  113. //
  114. // Called by queue instances to determine if they should close handles.
  115. //
  116. BOOL fShouldCloseHandle(
  117. DWORD cItemsPending,
  118. DWORD cItemsPendingAsyncCompletions,
  119. DWORD cCurrentMsgsOpen);
  120. };
  121. #endif //__HNDLMRMGR_H__