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.

186 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name :
  4. globlist.cxx
  5. Abstract:
  6. Global object list for DCOMADM.
  7. Author:
  8. Michael Thomas (michth) 4-June-1997
  9. --*/
  10. #include "precomp.hxx"
  11. #include <iadm.h>
  12. #include "coiadm.hxx"
  13. #include "admacl.hxx"
  14. CRITICAL_SECTION CADMCOMW::sm_csObjectListLock;
  15. LIST_ENTRY CADMCOMW::sm_ObjectList = { NULL, NULL };
  16. BOOL CADMCOMW::sm_fShutdownInProgress = FALSE;
  17. PTRACE_LOG CADMCOMW::sm_pDbgRefTraceLog = NULL;
  18. DECLARE_PLATFORM_TYPE();
  19. // static
  20. VOID
  21. CADMCOMW::InitObjectList()
  22. {
  23. InitializeListHead( &sm_ObjectList );
  24. INITIALIZE_CRITICAL_SECTION( &sm_csObjectListLock );
  25. sm_fShutdownInProgress = FALSE;
  26. sm_pDbgRefTraceLog = CreateRefTraceLog( 4096, 0 );
  27. NOTIFY_CONTEXT::Initialize();
  28. }
  29. // static
  30. VOID
  31. CADMCOMW::TerminateObjectList()
  32. {
  33. NOTIFY_CONTEXT::Terminate();
  34. DBG_ASSERT( IsListEmpty( &sm_ObjectList ) );
  35. sm_ObjectList.Flink = NULL;
  36. sm_ObjectList.Blink = NULL;
  37. DeleteCriticalSection( &sm_csObjectListLock );
  38. if( sm_pDbgRefTraceLog )
  39. {
  40. DestroyRefTraceLog( sm_pDbgRefTraceLog );
  41. sm_pDbgRefTraceLog = NULL;
  42. }
  43. }
  44. VOID
  45. CADMCOMW::AddObjectToList()
  46. {
  47. DBG_ASSERT( IsListEmpty( &m_ObjectListEntry ) );
  48. GetObjectListLock();
  49. AddRef();
  50. InsertHeadList( &sm_ObjectList, &m_ObjectListEntry );
  51. ReleaseObjectListLock();
  52. }
  53. BOOL
  54. CADMCOMW::RemoveObjectFromList(
  55. BOOL bIgnoreShutdown )
  56. {
  57. BOOL bRemovedIt = FALSE;
  58. // Stop getting and firing notifications.
  59. // Assuming this is a gracefull termination do not remove any pending notifications
  60. StopNotifications( FALSE );
  61. if( !bIgnoreShutdown && sm_fShutdownInProgress )
  62. {
  63. goto exit;
  64. }
  65. GetObjectListLock();
  66. if( bIgnoreShutdown || !sm_fShutdownInProgress )
  67. {
  68. if( !IsListEmpty( &m_ObjectListEntry ) )
  69. {
  70. bRemovedIt = TRUE;
  71. RemoveEntryList( &m_ObjectListEntry );
  72. InitializeListHead( &m_ObjectListEntry );
  73. }
  74. }
  75. ReleaseObjectListLock();
  76. if (bRemovedIt)
  77. {
  78. Release();
  79. }
  80. exit:
  81. return bRemovedIt;
  82. }
  83. // static
  84. VOID
  85. CADMCOMW::ShutDownObjects()
  86. {
  87. CADMCOMW * pCurrentObject = NULL;
  88. PLIST_ENTRY pCurrentEntry = NULL;
  89. //
  90. // Loop as long as we can get objects from the list
  91. //
  92. GetObjectListLock();
  93. sm_fShutdownInProgress = TRUE;
  94. ReleaseObjectListLock();
  95. // Remove all pending notifications
  96. NOTIFY_CONTEXT::RemoveAllWork();
  97. for ( ; ; )
  98. {
  99. GetObjectListLock();
  100. //
  101. // Remove the first object from the list
  102. //
  103. if( !IsListEmpty( &sm_ObjectList ) )
  104. {
  105. pCurrentEntry = sm_ObjectList.Flink;
  106. pCurrentObject = CONTAINING_RECORD( pCurrentEntry,
  107. CADMCOMW,
  108. m_ObjectListEntry );
  109. pCurrentObject->AddRef();
  110. DBG_REQUIRE( pCurrentObject->RemoveObjectFromList( TRUE ) );
  111. }
  112. ReleaseObjectListLock();
  113. if( pCurrentObject == NULL )
  114. {
  115. //
  116. // No more objects in the list.
  117. //
  118. break;
  119. }
  120. //
  121. // Shutdown the object. ForceTerminate will do a bounded wait
  122. // if the object is still being used.
  123. //
  124. pCurrentObject->ForceTerminate();
  125. pCurrentObject->Release();
  126. pCurrentObject = NULL;
  127. }
  128. }