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.

117 lines
3.2 KiB

  1. //******************************************************************************
  2. //
  3. // POSTPONE.CPP
  4. //
  5. // Copyright (C) 1996-1999 Microsoft Corporation
  6. //
  7. //******************************************************************************
  8. #include "precomp.h"
  9. #include <stdio.h>
  10. #include <ess.h>
  11. #include <postpone.h>
  12. HRESULT CPostponedList::AddRequest( CEssNamespace* pNamespace,
  13. ACQUIRE CPostponedRequest* pReq )
  14. {
  15. if ( pReq->DoesHoldTurn() )
  16. {
  17. m_cTurnsHeld++;
  18. }
  19. pReq->SetNamespace( pNamespace );
  20. if(!m_qpRequests.Enqueue(pReq))
  21. return WBEM_E_OUT_OF_MEMORY;
  22. else
  23. return WBEM_S_NO_ERROR;
  24. }
  25. HRESULT CPostponedList::Execute(CEssNamespace* pNamespace,
  26. EPostponedExecuteFlags eFlags,
  27. DELETE_ME CPostponedRequest** ppFailed)
  28. {
  29. if(ppFailed)
  30. *ppFailed = NULL;
  31. HRESULT hresGlobal = WBEM_S_NO_ERROR;
  32. while(m_qpRequests.GetQueueSize())
  33. {
  34. // Retrieve and remove the next request
  35. // ====================================
  36. CPostponedRequest* pReq = m_qpRequests.Dequeue();
  37. if ( pReq->DoesHoldTurn() )
  38. {
  39. _DBG_ASSERT( m_cTurnsHeld > 0 );
  40. m_cTurnsHeld--;
  41. }
  42. //
  43. // see if the namespace that postponed the request is different
  44. // from the one executing it. If it is, this is very bad. This
  45. // can happen in (faulty) cross namespace logic when one namespace is
  46. // executing an operation in the other, normally while holding
  47. // its own ns lock, and then the other fires the postponed
  48. // operations for itself and the original namespace which surely
  49. // was not intended. Some requests aren't namespace specific, so
  50. // it we don't do the check for these.
  51. //
  52. _DBG_ASSERT( pReq->GetNamespace() == NULL ||
  53. pReq->GetNamespace() == pNamespace );
  54. // Execute it
  55. // ==========
  56. HRESULT hres = pReq->Execute(pNamespace);
  57. if(FAILED(hres))
  58. {
  59. if(eFlags == e_StopOnFailure)
  60. {
  61. // Return the request and the error
  62. // ================================
  63. if(ppFailed)
  64. *ppFailed = pReq;
  65. else
  66. delete pReq;
  67. return hres;
  68. }
  69. else
  70. {
  71. // Record the request and the error
  72. // ================================
  73. if(ppFailed)
  74. {
  75. delete *ppFailed;
  76. *ppFailed = pReq;
  77. }
  78. else
  79. delete pReq;
  80. if(SUCCEEDED(hresGlobal))
  81. hresGlobal = hres;
  82. }
  83. }
  84. else
  85. {
  86. delete pReq;
  87. }
  88. }
  89. return hresGlobal;
  90. }
  91. HRESULT CPostponedList::Clear()
  92. {
  93. m_qpRequests.Clear();
  94. m_cTurnsHeld = 0;
  95. return WBEM_S_NO_ERROR;
  96. }