Source code of Windows XP (NT5)
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.

158 lines
2.6 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. dbginit.cxx
  6. Abstract:
  7. Debug Library initialization
  8. Author:
  9. Steve Kiraly (SteveKi) 24-May-1998
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. //
  15. // Debug library lock variable.
  16. //
  17. namespace
  18. {
  19. LONG DebugLibraryInitLock = 0;
  20. BOOL IsLibraryInitialized = FALSE;
  21. }
  22. /*++
  23. Title:
  24. DebugLibraryInitialize
  25. Routine Description:
  26. Initialize the debug library. Basically we need to have the
  27. library critical section initialized to prevent multiple threads
  28. from trying to access either the messaging initialization code
  29. or the internal heap initialization code.
  30. Arguments:
  31. None.
  32. Return Value:
  33. None.
  34. --*/
  35. extern "C"
  36. VOID
  37. DebugLibraryInitialize(
  38. VOID
  39. )
  40. {
  41. //
  42. // Is the library initialized.
  43. //
  44. if (!IsLibraryInitialized)
  45. {
  46. //
  47. // Only allow one thread to do the library initialization.
  48. //
  49. while (InterlockedCompareExchange(&DebugLibraryInitLock, 1, 0))
  50. {
  51. Sleep(1);
  52. }
  53. //
  54. // We must re-check is, to prevent second thread from doing
  55. // the initialization as well.
  56. //
  57. if (!IsLibraryInitialized)
  58. {
  59. //
  60. // Initialize the ciritical section
  61. //
  62. GlobalCriticalSection.Initialize();
  63. //
  64. // Initalize the debug heap.
  65. //
  66. DebugLibraryInitializeHeap();
  67. //
  68. // Mark the library as initialized.
  69. //
  70. IsLibraryInitialized = TRUE;
  71. }
  72. //
  73. // Release the library init lock.
  74. //
  75. DebugLibraryInitLock = 0;
  76. }
  77. }
  78. /*++
  79. Title:
  80. DebugLibraryRelease
  81. Routine Description:
  82. Release any resorces in the debug library. Callers should call
  83. this function to properly shut down the library. Callers should
  84. not call any function in the library after this call.
  85. Arguments:
  86. None.
  87. Return Value:
  88. None.
  89. --*/
  90. extern "C"
  91. VOID
  92. DebugLibraryRelease(
  93. VOID
  94. )
  95. {
  96. //
  97. // Relese the message instance.
  98. //
  99. TDebugMsg_Release();
  100. //
  101. // Walk the internal heap, if the Display library
  102. // errors flag is enabled then the heap contents
  103. // are dummped to the debug device.
  104. //
  105. DebugLibraryWalkHeap();
  106. //
  107. // Release the internal heap.
  108. //
  109. DebugLibraryDestroyHeap();
  110. //
  111. // Release the critical section.
  112. //
  113. GlobalCriticalSection.Release();
  114. //
  115. // Mark the library as not initialized.
  116. //
  117. IsLibraryInitialized = FALSE;
  118. }