Windows NT 4.0 source code leak
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.

175 lines
4.2 KiB

4 years ago
  1. ///+---------------------------------------------------------------------------
  2. //
  3. // File: olesem.cxx
  4. //
  5. // Contents: Implementation of semaphore classes for use in OLE code
  6. //
  7. // Functions: COleStaticMutexSem::Destroy
  8. // COleStaticMutexSem::Request
  9. // COleStaticMutexSem::Init
  10. // COleDebugMutexSem::COleDebugMutexSem
  11. //
  12. // History: 14-Dec-95 Jeffe Initial entry, derived from
  13. // sem32.hxx by AlexT.
  14. //
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <windows.h>
  18. #include <debnot.h>
  19. #include <olesem.hxx>
  20. //
  21. // Global state for the mutex package
  22. //
  23. //
  24. // List of initialized static mutexes (which must be destroyed
  25. // during DLL exit). We know that PROCESS_ATTACH and PROCESS_DETACH
  26. // are thread-safe, so we don't protect this list with a critical section.
  27. //
  28. COleStaticMutexSem * g_pInitializedStaticMutexList = NULL;
  29. #if DBG
  30. //
  31. // Flag used to indicate if we're past executing the C++ constructors
  32. // during DLL initialization
  33. //
  34. DLL_STATE g_fDllState = DLL_STATE_STATIC_CONSTRUCTING;
  35. #endif
  36. //
  37. // Semaphore used to protect the creation of other semaphores
  38. //
  39. CRITICAL_SECTION g_OleMutexCreationSem;
  40. //+---------------------------------------------------------------------------
  41. //
  42. // Member: COleStaticMutexSem::Destroy
  43. //
  44. // Synopsis: Releases a semaphore's critical section.
  45. //
  46. // History: 14-Dec-1995 Jeffe
  47. //
  48. //----------------------------------------------------------------------------
  49. void COleStaticMutexSem::Destroy()
  50. {
  51. if (_fInitialized)
  52. {
  53. DeleteCriticalSection (&_cs);
  54. _fInitialized = FALSE;
  55. }
  56. }
  57. //+---------------------------------------------------------------------------
  58. //
  59. // Member: COleStaticMutexSem::Request
  60. //
  61. // Synopsis: Acquire the semaphore. If another thread already has it,
  62. // wait until it is released. Initialize the semaphore if it
  63. // isn't already initialized.
  64. //
  65. // History: 14-Dec-1995 Jeffe
  66. //
  67. //----------------------------------------------------------------------------
  68. void COleStaticMutexSem::Request()
  69. {
  70. if (!_fInitialized)
  71. {
  72. EnterCriticalSection (&g_OleMutexCreationSem);
  73. if (!_fInitialized) {
  74. Init();
  75. }
  76. LeaveCriticalSection (&g_OleMutexCreationSem);
  77. }
  78. EnterCriticalSection (&_cs);
  79. }
  80. //+---------------------------------------------------------------------------
  81. //
  82. // Member: COleStaticMutexSem::Init
  83. //
  84. // Synopsis: Initialize semaphore's critical section
  85. //
  86. // History: 14-Dec-1995 Jeffe
  87. //
  88. //----------------------------------------------------------------------------
  89. void COleStaticMutexSem::Init()
  90. {
  91. InitializeCriticalSection (&_cs);
  92. _fInitialized = TRUE;
  93. if (!_fAutoDestruct)
  94. {
  95. //
  96. // We don't need to protect this list with a mutex, since it's only
  97. // manipulated during DLL attach/detach, which is single threaded by
  98. // the platform.
  99. //
  100. pNextMutex = g_pInitializedStaticMutexList;
  101. g_pInitializedStaticMutexList = this;
  102. }
  103. }
  104. #ifdef _CHICAGO_
  105. //+---------------------------------------------------------------------------
  106. //
  107. // Member: COleStaticMutexSem::ReleaseFn
  108. //
  109. // Synopsis: Release the semaphore(non inline version) used only by rpccall.asm
  110. //
  111. // History: 14-Dec-1995 Jeffe
  112. //
  113. //----------------------------------------------------------------------------
  114. void COleStaticMutexSem::ReleaseFn()
  115. {
  116. LeaveCriticalSection (&_cs);
  117. }
  118. #endif
  119. #if DBG==1
  120. //+---------------------------------------------------------------------------
  121. //
  122. // Member: COleDebugMutexSem::COleDebugMutexSem
  123. //
  124. // Synopsis: Mark the mutex as dynamic...which will prevent it from being
  125. // added to the static mutex cleanup list on DLL unload.
  126. //
  127. // History: 14-Dec-1995 Jeffe
  128. //
  129. // Notes: We don't care that this has a constructor, as it won't be run
  130. // in retail builds.
  131. //
  132. //----------------------------------------------------------------------------
  133. COleDebugMutexSem::COleDebugMutexSem()
  134. {
  135. Win4Assert (g_fDllState == DLL_STATE_STATIC_CONSTRUCTING);
  136. _fAutoDestruct = TRUE;
  137. _fInitialized = FALSE;
  138. }
  139. #endif // DBG==1