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.

129 lines
4.1 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. //
  4. // File: aqstats.cpp
  5. //
  6. // Description: Implementation of CAQStats/
  7. //
  8. // Author: Mike Swafford (MikeSwa)
  9. //
  10. // History:
  11. // 11/3/98 - MikeSwa Created
  12. //
  13. // Copyright (C) 1998 Microsoft Corporation
  14. //
  15. //-----------------------------------------------------------------------------
  16. #include "aqprecmp.h"
  17. #include "aqstats.h"
  18. #include "aqutil.h"
  19. CAQStats::CAQStats()
  20. {
  21. m_dwSignature = AQSTATS_SIG;
  22. Reset();
  23. }
  24. void CAQStats::Reset()
  25. {
  26. m_dwHighestPri = 0;
  27. m_dwNotifyType = NotifyTypeUndefined;
  28. m_uliVolume.QuadPart = 0;
  29. m_pvContext = NULL;
  30. m_cMsgs = 0;
  31. m_cRetryMsgs = 0;
  32. m_cOtherDomainsMsgSpread = 0;
  33. ZeroMemory(m_rgcMsgPriorities, NUM_PRIORITIES*sizeof(DWORD));
  34. };
  35. //---[ CAQStats::UpdateRetryStats ]------------------------------------------
  36. //
  37. //
  38. // Description:
  39. // Used to provide "thread-safe" update on retry queue.
  40. // This function only updates m_cRetryMsg.
  41. // One message at a time. Only called after enqueu/dequeue of retry queue.
  42. // There's no need to adjust other members
  43. //
  44. // Parameters:
  45. // fAdd TRUE if update reflects addition of msgs into retry queue
  46. // FALSE if update reflects removal of msgs into retry queue
  47. // Returns:
  48. // -
  49. //
  50. //-----------------------------------------------------------------------------
  51. void CAQStats::UpdateRetryStats(BOOL fAdd)
  52. {
  53. dwInterlockedAddSubtractDWORD(&m_cRetryMsgs, 1, fAdd);
  54. }
  55. //---[ CAQStats::UpdateStats ]------------------------------------------
  56. //
  57. //
  58. // Description:
  59. // Used to provide "thread-safe" update.
  60. //
  61. // NOTE: It is possible that m_dwHighestPri will not be entirely correct
  62. // if multple threads are changing the max priority at the same time, but
  63. // was deemed non-crucial.
  64. // Parameters:
  65. // paqstats CAQStats to update data from
  66. // fAdd TRUE if update reflects addition of msgs
  67. // FALSE if update reflects removal of msgs
  68. // Returns:
  69. // -
  70. // History:
  71. // 11/3/98 - MikeSwa Created
  72. //
  73. //-----------------------------------------------------------------------------
  74. void CAQStats::UpdateStats(CAQStats *paqstat, BOOL fAdd)
  75. {
  76. DWORD dwPri = 0;
  77. DWORD cTmpMsgCount = 0;
  78. DWORD dwNewHighestPri = 0;
  79. dwInterlockedAddSubtractDWORD(&m_cMsgs, paqstat->m_cMsgs, fAdd);
  80. dwInterlockedAddSubtractDWORD(&m_cOtherDomainsMsgSpread, paqstat->m_cOtherDomainsMsgSpread, fAdd);
  81. dwInterlockedAddSubtractDWORD(&m_cRetryMsgs, paqstat->m_cRetryMsgs, fAdd);
  82. //When adding new messages, finding the highest priority is easy
  83. dwPri = m_dwHighestPri;
  84. if (fAdd && (paqstat->m_dwHighestPri > dwPri))
  85. {
  86. InterlockedCompareExchange((PLONG) &m_dwHighestPri,
  87. (LONG) paqstat->m_dwHighestPri,
  88. (LONG) dwPri);
  89. }
  90. //Count down from highest prioriry
  91. for (DWORD iPri = 0; iPri < NUM_PRIORITIES; iPri++)
  92. {
  93. if (paqstat->m_rgcMsgPriorities[iPri])
  94. {
  95. cTmpMsgCount = dwInterlockedAddSubtractDWORD(&(m_rgcMsgPriorities[iPri]),
  96. paqstat->m_rgcMsgPriorities[iPri], fAdd);
  97. if (!fAdd && (cTmpMsgCount != paqstat->m_rgcMsgPriorities[iPri]))
  98. {
  99. if (dwNewHighestPri < iPri)
  100. dwNewHighestPri = dwNewHighestPri;
  101. }
  102. }
  103. else if (!fAdd && m_rgcMsgPriorities[iPri] && (dwNewHighestPri < iPri))
  104. {
  105. dwNewHighestPri = dwNewHighestPri;
  106. }
  107. }
  108. //See if removing message has changed the highest priority
  109. if (!fAdd && (dwNewHighestPri < dwPri))
  110. {
  111. InterlockedCompareExchange((PLONG) &m_dwHighestPri,
  112. (LONG) dwNewHighestPri,
  113. (LONG) dwPri);
  114. }
  115. //Update total volume
  116. InterlockedAddSubtractULARGE(&m_uliVolume, &(paqstat->m_uliVolume), fAdd);
  117. }