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.

118 lines
2.9 KiB

  1. #include "precomp.h"
  2. #include "mcinc.h"
  3. #include "globals.h"
  4. DWORD g_dwPerfFlags;
  5. CRITICAL_SECTION CMarsGlobalCritSect::m_CS;
  6. IGlobalInterfaceTable *CMarsGlobalsManager::ms_pGIT = NULL;
  7. CMarsGlobalCritSect *CMarsGlobalsManager::m_pCS;
  8. EXTERN_C HINSTANCE g_hinst = NULL;
  9. EXTERN_C HINSTANCE g_hinstBorg = NULL;
  10. HPALETTE g_hpalHalftone = NULL;
  11. HANDLE g_hScriptEvents = INVALID_HANDLE_VALUE;
  12. static LONG s_cProcessRef = 0;
  13. static DWORD s_dwParkingThreadId = 0;
  14. LONG ProcessAddRef()
  15. {
  16. InterlockedIncrement(&s_cProcessRef);
  17. return s_cProcessRef;
  18. }
  19. LONG ProcessRelease()
  20. {
  21. ATLASSERT(s_cProcessRef > 0);
  22. InterlockedDecrement(&s_cProcessRef);
  23. if (s_cProcessRef == 0)
  24. {
  25. PostThreadMessage(s_dwParkingThreadId, WM_NULL, 0, 0);
  26. }
  27. return s_cProcessRef;
  28. }
  29. LONG GetProcessRefCount()
  30. {
  31. return s_cProcessRef;
  32. }
  33. void SetParkingThreadId(DWORD dwThreadId)
  34. {
  35. s_dwParkingThreadId = dwThreadId;
  36. }
  37. void CMarsGlobalsManager::Initialize(void)
  38. {
  39. // We have to use a pointer because we need
  40. // the constructor to get called (the thing has a vtable) and that
  41. // won't happen for global static objects since we're CRT-less.
  42. m_pCS = new CMarsGlobalCritSect;
  43. // We're REALLY in trouble if we can't get this thing created...
  44. ATLASSERT(m_pCS);
  45. }
  46. void CMarsGlobalsManager::Teardown(void)
  47. {
  48. ATLASSERT(m_pCS);
  49. if (m_pCS)
  50. {
  51. m_pCS->Enter();
  52. }
  53. if (NULL != ms_pGIT)
  54. {
  55. ms_pGIT->Release();
  56. ms_pGIT = NULL;
  57. }
  58. // Leave before we delete the Critical Section object.
  59. if (m_pCS)
  60. {
  61. m_pCS->Leave();
  62. }
  63. delete m_pCS;
  64. }
  65. //----------------------------------------------------------------------------
  66. // Inform everyone who registered that it is time to clean up their globals
  67. //----------------------------------------------------------------------------
  68. HRESULT CMarsGlobalsManager::Passivate()
  69. {
  70. HRESULT hr = S_OK;
  71. ATLASSERT(m_pCS);
  72. CMarsAutoCSGrabber csGrabber(m_pCS);
  73. return hr;
  74. }
  75. //----------------------------------------------------------------------------
  76. // Return the Global Interface Table object
  77. //----------------------------------------------------------------------------
  78. IGlobalInterfaceTable *CMarsGlobalsManager::GIT(void)
  79. {
  80. ATLASSERT(m_pCS);
  81. CMarsAutoCSGrabber csGrabber(m_pCS);
  82. if (NULL == ms_pGIT)
  83. {
  84. HRESULT hr = CoCreateInstance(CLSID_StdGlobalInterfaceTable, NULL, CLSCTX_INPROC_SERVER,
  85. IID_IGlobalInterfaceTable, (void **)&ms_pGIT);
  86. if (FAILED(hr))
  87. {
  88. ATLASSERT(false);
  89. }
  90. }
  91. // NULL if there was a failure, non-NULL otherwise.
  92. // NOTE: We are NOT returning an AddRef()'d pointer here!!! Caller cannot release.
  93. return ms_pGIT;
  94. } // GIT