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.

122 lines
3.1 KiB

  1. //#---------------------------------------------------------------
  2. // File: CDescrip.cpp
  3. //
  4. // Synopsis: This file implements the CDescriptor class
  5. //
  6. // Copyright (C) 1995 Microsoft Corporation
  7. // All rights reserved.
  8. //
  9. // Authors: HowardCu t-alexwe
  10. //----------------------------------------------------------------
  11. #ifdef THIS_FILE
  12. #undef THIS_FILE
  13. #endif
  14. static char __szTraceSourceFile[] = __FILE__;
  15. #define THIS_FILE __szTraceSourceFile
  16. #include <windows.h>
  17. #include <stdio.h>
  18. #include "cdescrip.h"
  19. #include "cobjid.h"
  20. #include "cpool.h"
  21. #include "dbgtrace.h"
  22. static DWORD g_dwUniqueIdFactory = 1;
  23. static CRITICAL_SECTION g_critFactory;
  24. static BOOL g_bUseUniqueIDs = FALSE;
  25. //+---------------------------------------------------------------
  26. //
  27. // Function: InitializeUniqueIDs
  28. //
  29. // Synopsis: Called to enable unique IDs inside CDescriptor's
  30. //
  31. // Arguments: void
  32. //
  33. // Returns: void
  34. //
  35. //----------------------------------------------------------------
  36. void InitializeUniqueIDs( void )
  37. {
  38. InitializeCriticalSection( &g_critFactory );
  39. g_bUseUniqueIDs = TRUE;
  40. }
  41. //+---------------------------------------------------------------
  42. //
  43. // Function: TerminateUniqueIDs
  44. //
  45. // Synopsis: Called to cleanup unique IDs inside CDescriptor's
  46. //
  47. // Arguments: void
  48. //
  49. // Returns: void
  50. //
  51. //----------------------------------------------------------------
  52. void TerminateUniqueIDs( void )
  53. {
  54. g_bUseUniqueIDs = FALSE;
  55. DeleteCriticalSection( &g_critFactory );
  56. }
  57. //+---------------------------------------------------------------
  58. //
  59. // Function: CDescriptor
  60. //
  61. // Synopsis: constructor is never called due to virtual array alloc
  62. // Rather a void * will be cast to a CDescriptor *
  63. // Arguments: void
  64. //
  65. // Returns: void
  66. //
  67. // History: HowardCu Created 8 May 1995
  68. //
  69. //----------------------------------------------------------------
  70. CDescriptor::CDescriptor( DWORD dwSignature ) : m_dwSignature( dwSignature )
  71. {
  72. TraceFunctEnter( "CDescriptor::CDescriptor" );
  73. StateTrace((LPARAM) this, "m_eState = DESCRIPTOR_INUSE");
  74. m_eState = DESCRIPTOR_INUSE;
  75. if ( g_bUseUniqueIDs == TRUE )
  76. {
  77. EnterCriticalSection( &g_critFactory );
  78. m_dwUniqueObjectID = g_dwUniqueIdFactory++;
  79. LeaveCriticalSection( &g_critFactory );
  80. }
  81. TraceFunctLeave();
  82. }
  83. //+---------------------------------------------------------------
  84. //
  85. // Function: ~CDescriptor
  86. //
  87. // Synopsis: destructor should never be called. We just decommit
  88. // virtual array
  89. //
  90. // Arguments: void
  91. //
  92. // Returns: void
  93. //
  94. // History: HowardCu Created 8 May 1995
  95. //
  96. //----------------------------------------------------------------
  97. CDescriptor::~CDescriptor(
  98. void
  99. )
  100. {
  101. TraceFunctEnter( "CDescriptor::~CDescriptor" );
  102. _ASSERT( m_eState == DESCRIPTOR_INUSE );
  103. StateTrace((LPARAM) this, "m_eState = DESCRIPTOR_FREE");
  104. m_eState = DESCRIPTOR_FREE;
  105. m_dwUniqueObjectID = 0;
  106. TraceFunctLeave();
  107. }