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.

160 lines
3.1 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: AsyncOp.cpp
  6. * Content: Async Operation routines
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 04/08/00 mjn Created
  12. * 04/11/00 mjn Added DIRECTNETOBJECT bilink for CAsyncOps
  13. * 05/02/00 mjn Added m_pConnection to track Connection over life of AsyncOp
  14. * 07/27/00 mjn Changed locking for parent/child bilinks
  15. * 08/05/00 RichGr IA64: Use %p format specifier in DPFs for 32/64-bit pointers and handles.
  16. *@@END_MSINTERNAL
  17. *
  18. ***************************************************************************/
  19. #include "dncorei.h"
  20. // CAsyncOp::ReturnSelfToPool
  21. //
  22. // Return object to FPM
  23. #undef DPF_MODNAME
  24. #define DPF_MODNAME "CAsyncOp::ReturnSelfToPool"
  25. void CAsyncOp::ReturnSelfToPool( void )
  26. {
  27. g_AsyncOpPool.Release( this );
  28. }
  29. #undef DPF_MODNAME
  30. #define DPF_MODNAME "CAsyncOp::Release"
  31. void CAsyncOp::Release(void)
  32. {
  33. LONG lRefCount;
  34. DNASSERT(m_lRefCount > 0);
  35. lRefCount = DNInterlockedDecrement(const_cast<LONG*>(&m_lRefCount));
  36. DPFX(DPFPREP, 3,"[0x%p] RefCount [0x%lx]", this, lRefCount);
  37. if (lRefCount == 0)
  38. {
  39. DNASSERT( m_bilinkActiveList.IsEmpty() );
  40. #ifdef DBG
  41. //
  42. // Remove from the bilink of outstanding AsyncOps
  43. //
  44. DNEnterCriticalSection(&m_pdnObject->csAsyncOperations);
  45. Lock();
  46. m_bilinkAsyncOps.RemoveFromList();
  47. DNLeaveCriticalSection(&m_pdnObject->csAsyncOperations);
  48. Unlock();
  49. #endif // DBG
  50. if (m_pfnCompletion)
  51. {
  52. (m_pfnCompletion)(m_pdnObject,this);
  53. m_pfnCompletion = NULL;
  54. }
  55. if (m_phr)
  56. {
  57. *m_phr = m_hr;
  58. }
  59. if (m_pSyncEvent)
  60. {
  61. m_pSyncEvent->Set();
  62. m_pSyncEvent = NULL;
  63. }
  64. if (m_pRefCountBuffer)
  65. {
  66. m_pRefCountBuffer->Release();
  67. m_pRefCountBuffer = NULL;
  68. }
  69. if (m_pConnection)
  70. {
  71. m_pConnection->Release();
  72. m_pConnection = NULL;
  73. }
  74. if (m_pSP)
  75. {
  76. m_pSP->Release();
  77. m_pSP = NULL;
  78. }
  79. if (m_pParent)
  80. {
  81. Orphan();
  82. m_pParent->Release();
  83. m_pParent = NULL;
  84. }
  85. m_dwFlags = 0;
  86. m_lRefCount = 0;
  87. ReturnSelfToPool();
  88. }
  89. };
  90. #undef DPF_MODNAME
  91. #define DPF_MODNAME "CAsyncOp::Orphan"
  92. void CAsyncOp::Orphan( void )
  93. {
  94. if (m_pParent)
  95. {
  96. m_pParent->Lock();
  97. m_bilinkChildren.RemoveFromList();
  98. m_pParent->Unlock();
  99. }
  100. }
  101. #undef DPF_MODNAME
  102. #define DPF_MODNAME "CAsyncOp::SetConnection"
  103. void CAsyncOp::SetConnection( CConnection *const pConnection )
  104. {
  105. if (pConnection)
  106. {
  107. pConnection->AddRef();
  108. }
  109. m_pConnection = pConnection;
  110. }
  111. #undef DPF_MODNAME
  112. #define DPF_MODNAME "CAsyncOp::SetSP"
  113. void CAsyncOp::SetSP( CServiceProvider *const pSP )
  114. {
  115. if (pSP)
  116. {
  117. pSP->AddRef();
  118. }
  119. m_pSP = pSP;
  120. }
  121. #undef DPF_MODNAME
  122. #define DPF_MODNAME "CAsyncOp::SetRefCountBuffer"
  123. void CAsyncOp::SetRefCountBuffer( CRefCountBuffer *const pRefCountBuffer )
  124. {
  125. if (pRefCountBuffer)
  126. {
  127. pRefCountBuffer->AddRef();
  128. }
  129. m_pRefCountBuffer = pRefCountBuffer;
  130. }