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.

113 lines
2.8 KiB

  1. //=============================================================================
  2. //
  3. // Copyright (c) 1996-1999, Microsoft Corporation, All rights reserved
  4. //
  5. // EQUEUE.CPP
  6. //
  7. // This file implements the classes for a queue of events which have matched
  8. // some of the filters and will have to be dispatched.
  9. //
  10. // See equeue.h for documentation
  11. //
  12. // History:
  13. //
  14. // 11/27/96 a-levn Compiles.
  15. //
  16. //=============================================================================
  17. #include "precomp.h"
  18. #include <stdio.h>
  19. #include "ess.h"
  20. #include "equeue.h"
  21. #include <cominit.h>
  22. #include "NCEvents.h"
  23. CEventQueue::CDeliverRequest::CDeliverRequest(CQueueingEventSink* pConsumer)
  24. : m_pConsumer(pConsumer)
  25. {
  26. m_pConsumer->AddRef();
  27. }
  28. CEventQueue::CDeliverRequest::~CDeliverRequest()
  29. {
  30. m_pConsumer->Release();
  31. }
  32. HRESULT CEventQueue::CDeliverRequest::Execute()
  33. {
  34. return m_pConsumer->DeliverAll();
  35. }
  36. //*****************************************************************************
  37. //************************ CEventQueue ****************************************
  38. //*****************************************************************************
  39. CEventQueue::CEventQueue(CEss* pEss) : m_pEss(pEss)
  40. {
  41. SetThreadLimits(100, 100, -1);
  42. }
  43. HRESULT CEventQueue::InitializeThread()
  44. {
  45. HRESULT hr;
  46. if (FAILED(hr = CExecQueue::InitializeThread())) return hr;
  47. //
  48. // Report the MSFT_WmiThreadPoolThreadCreated event.
  49. //
  50. FIRE_NCEVENT( g_hNCEvents[MSFT_WmiThreadPoolThreadCreated],
  51. WMI_SENDCOMMIT_SET_NOT_REQUIRED,
  52. GetCurrentThreadId());
  53. return S_OK;
  54. }
  55. void CEventQueue::UninitializeThread()
  56. {
  57. //
  58. // Report the MSFT_WmiThreadPoolThreadDeleted event.
  59. //
  60. FIRE_NCEVENT( g_hNCEvents[MSFT_WmiThreadPoolThreadDeleted],
  61. WMI_SENDCOMMIT_SET_NOT_REQUIRED,
  62. GetCurrentThreadId() );
  63. CExecQueue::UninitializeThread();
  64. }
  65. void CEventQueue::ThreadMain(CThreadRecord* pRecord)
  66. {
  67. try
  68. {
  69. CExecQueue::ThreadMain(pRecord);
  70. }
  71. catch(...)
  72. {
  73. // Exit this thread gracefully
  74. // ===========================
  75. ShutdownThread(pRecord);
  76. }
  77. }
  78. HRESULT CEventQueue::EnqueueDeliver(CQueueingEventSink* pConsumer)
  79. {
  80. // Create a new request
  81. // ====================
  82. HRESULT hr;
  83. CDeliverRequest* pRequest = new CDeliverRequest(pConsumer);
  84. if(pRequest == NULL)
  85. return WBEM_E_OUT_OF_MEMORY;
  86. if FAILED(hr = CExecQueue::Enqueue(pRequest))
  87. {
  88. delete pRequest;
  89. }
  90. return hr;
  91. }
  92. void CEventQueue::DumpStatistics(FILE* f, long lFlags)
  93. {
  94. fprintf(f, "%d requests (%d threads) on the main queue\n", m_lNumRequests,
  95. m_lNumThreads);
  96. }