Source code of Windows XP (NT5)
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.

190 lines
2.2 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. refb.cxx
  5. Abstract:
  6. Reference counting blob class
  7. Author:
  8. Philippe Choquier (phillich) 11-sep-1996
  9. --*/
  10. #include "tcpdllp.hxx"
  11. #pragma hdrstop
  12. #include <refb.hxx>
  13. RefBlob::RefBlob(
  14. )
  15. /*++
  16. Description:
  17. Constructor for RefBlob
  18. Arguments:
  19. None
  20. Returns:
  21. Nothing
  22. --*/
  23. {
  24. m_lRef = 0;
  25. m_pvBlob = 0;
  26. m_dwSize = 0;
  27. m_pfnFree = NULL;
  28. }
  29. RefBlob::~RefBlob(
  30. )
  31. /*++
  32. Description:
  33. Destructor for RefBlob
  34. Arguments:
  35. None
  36. Returns:
  37. Nothing
  38. --*/
  39. {
  40. }
  41. BOOL
  42. RefBlob::Init(
  43. LPVOID pv,
  44. DWORD sz,
  45. PFN_FREE_BLOB pFn
  46. )
  47. /*++
  48. Description:
  49. Initialize a RefBlob
  50. ownership of buffer pointed to by pv is transferred
  51. to this object. buffer must have been allocated using
  52. LocalAlloc( LMEM_FIXED, )
  53. Arguments:
  54. pv - pointer to blob
  55. sz - size of blob
  56. pFn - ptr to function to call to free blob
  57. Returns:
  58. TRUE if success, otherwise FALSE
  59. --*/
  60. {
  61. m_pvBlob = pv;
  62. m_dwSize = sz;
  63. m_pfnFree = pFn;
  64. AddRef();
  65. return TRUE;
  66. }
  67. VOID
  68. RefBlob::AddRef(
  69. VOID
  70. )
  71. /*++
  72. Description:
  73. Add a reference to this object
  74. Arguments:
  75. None
  76. Returns:
  77. Nothing
  78. --*/
  79. {
  80. InterlockedIncrement( &m_lRef );
  81. }
  82. VOID
  83. RefBlob::Release(
  84. VOID
  85. )
  86. /*++
  87. Description:
  88. Remove a reference to this object
  89. When the reference count drops to zero
  90. the object is destroyed, blob memory freed
  91. Arguments:
  92. None
  93. Returns:
  94. Nothing
  95. --*/
  96. {
  97. if ( !InterlockedDecrement( &m_lRef ) )
  98. {
  99. if ( m_pfnFree )
  100. {
  101. (m_pfnFree)( m_pvBlob );
  102. }
  103. else
  104. {
  105. LocalFree( m_pvBlob );
  106. }
  107. delete this;
  108. }
  109. }
  110. LPVOID
  111. RefBlob::QueryPtr(
  112. )
  113. /*++
  114. Description:
  115. Returns a ptr to blob
  116. Arguments:
  117. None
  118. Returns:
  119. ptr to blob
  120. --*/
  121. {
  122. return m_pvBlob;
  123. }
  124. DWORD
  125. RefBlob::QuerySize(
  126. )
  127. /*++
  128. Description:
  129. Returns a blob size
  130. Arguments:
  131. None
  132. Returns:
  133. size of blob
  134. --*/
  135. {
  136. return m_dwSize;
  137. }