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.

134 lines
2.7 KiB

  1. //=================================================================
  2. //
  3. // refptrlite.CPP - Implementation of CRefPtrLite class
  4. //
  5. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. // Revisions: 10/15/97 a-sanjes Created
  8. //
  9. //=================================================================
  10. #include "precomp.h"
  11. #include <assertbreak.h>
  12. #include "refptrlite.h"
  13. ////////////////////////////////////////////////////////////////////////
  14. //
  15. // Function: CRefPtrLite::CRefPtrLite
  16. //
  17. // Class Constructor.
  18. //
  19. // Inputs: None.
  20. //
  21. // Outputs: None.
  22. //
  23. // Return: None.
  24. //
  25. // Comments: None.
  26. //
  27. ////////////////////////////////////////////////////////////////////////
  28. CRefPtrLite::CRefPtrLite( void )
  29. : m_lRefCount( 1 ) // Our initial ref count is always 1
  30. {
  31. }
  32. ////////////////////////////////////////////////////////////////////////
  33. //
  34. // Function: CRefPtrLite::~CRefPtrLite
  35. //
  36. // Class Destructor.
  37. //
  38. // Inputs: None.
  39. //
  40. // Outputs: None.
  41. //
  42. // Return: None.
  43. //
  44. // Comments: None.
  45. //
  46. ////////////////////////////////////////////////////////////////////////
  47. CRefPtrLite::~CRefPtrLite( void )
  48. {
  49. }
  50. ////////////////////////////////////////////////////////////////////////
  51. //
  52. // Function: CRefPtrLite::OnFinalRelease
  53. //
  54. // Virtual function called by Release() when our RefCount reaches 0.
  55. //
  56. // Inputs: None.
  57. //
  58. // Outputs: None.
  59. //
  60. // Return: None.
  61. //
  62. // Comments: Override if you want, but always call down to the base
  63. // implementation and let it call delete on 'this'.
  64. //
  65. ////////////////////////////////////////////////////////////////////////
  66. void CRefPtrLite::OnFinalRelease( void )
  67. {
  68. delete this;
  69. }
  70. ////////////////////////////////////////////////////////////////////////
  71. //
  72. // Function: CRefPtrLite::AddRef
  73. //
  74. // Increases our Reference count by one.
  75. //
  76. // Inputs: None.
  77. //
  78. // Outputs: None.
  79. //
  80. // Return: None.
  81. //
  82. // Comments:
  83. //
  84. ////////////////////////////////////////////////////////////////////////
  85. LONG CRefPtrLite::AddRef( void )
  86. {
  87. LONG nRet = InterlockedIncrement(&m_lRefCount);
  88. return nRet;
  89. }
  90. ////////////////////////////////////////////////////////////////////////
  91. //
  92. // Function: CRefPtrLite::Release
  93. //
  94. // Decreases our Reference count by one.
  95. //
  96. // Inputs: None.
  97. //
  98. // Outputs: None.
  99. //
  100. // Return: None.
  101. //
  102. // Comments:
  103. //
  104. ////////////////////////////////////////////////////////////////////////
  105. LONG CRefPtrLite::Release( void )
  106. {
  107. LONG nRet;
  108. BOOL fFinalRelease = ( (nRet = InterlockedDecrement(&m_lRefCount)) == 0 );
  109. ASSERT_BREAK(nRet >= 0);
  110. if ( fFinalRelease )
  111. {
  112. OnFinalRelease();
  113. }
  114. return nRet;
  115. }