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.

102 lines
2.6 KiB

  1. //---------------------------------------------------------------------------
  2. // Globals.cpp : Global information
  3. //
  4. // Copyright (c) 1996 Microsoft Corporation, All Rights Reserved
  5. // Developed by Sheridan Software Systems, Inc.
  6. //---------------------------------------------------------------------------
  7. #include "stdafx.h"
  8. SZTHISFILE
  9. // our global memory allocator and global memory pool
  10. //
  11. HANDLE g_hHeap;
  12. LPMALLOC g_pMalloc;
  13. HINSTANCE g_hinstance;
  14. //Count number of objects and number of locks.
  15. ULONG g_cLockCount=0;
  16. ULONG g_cObjectCount=0;
  17. CRITICAL_SECTION g_CriticalSection;
  18. // frequently used large integers
  19. //
  20. LARGE_INTEGER g_liMinus = {(ULONG)-1, -1}; // minus one
  21. LARGE_INTEGER g_liZero = {0, 0}; // - zero -
  22. LARGE_INTEGER g_liPlus = {0, 1}; // plus one
  23. //=--------------------------------------------------------------------------=
  24. // VDInitGlobals
  25. //=--------------------------------------------------------------------------=
  26. // Initialize global variables
  27. //
  28. // Parameters:
  29. // hinstResource - [in] The instance handle that contains resource strings
  30. //
  31. // Output:
  32. // TRUE if successful otherwise FALSE
  33. //
  34. BOOL VDInitGlobals(HINSTANCE hinstance)
  35. {
  36. g_pMalloc = NULL;
  37. g_hinstance = hinstance;
  38. g_hHeap = GetProcessHeap();
  39. if (!g_hHeap)
  40. {
  41. FAIL("Couldn't get Process Heap.");
  42. return FALSE;
  43. }
  44. InitializeCriticalSection(&g_CriticalSection);
  45. return TRUE;
  46. }
  47. //=--------------------------------------------------------------------------=
  48. // VDReleaseGlobals
  49. //=--------------------------------------------------------------------------=
  50. //
  51. void VDReleaseGlobals()
  52. {
  53. if (g_pMalloc)
  54. {
  55. g_pMalloc->Release();
  56. g_pMalloc = NULL;
  57. }
  58. #ifdef _DEBUG
  59. DumpObjectCounters();
  60. #endif // _DEBUG
  61. DeleteCriticalSection(&g_CriticalSection);
  62. }
  63. //=--------------------------------------------------------------------------=
  64. // VDUpdateObjectCount increments/decrements global object count
  65. //=--------------------------------------------------------------------------=
  66. //
  67. void VDUpdateObjectCount(int cChange)
  68. {
  69. EnterCriticalSection(&g_CriticalSection);
  70. g_cObjectCount += cChange;
  71. // get global malloc pointer object count greater than zero
  72. if (!g_pMalloc && g_cObjectCount > 0)
  73. {
  74. CoGetMalloc(MEMCTX_TASK, &g_pMalloc);
  75. }
  76. else
  77. // release hold on global malloc pointer when no more objects
  78. if (0 == g_cObjectCount && g_pMalloc)
  79. {
  80. g_pMalloc->Release();
  81. g_pMalloc = NULL;
  82. }
  83. LeaveCriticalSection(&g_CriticalSection);
  84. }