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.

82 lines
1.4 KiB

  1. // File: refcount.cpp
  2. //
  3. // RefCount class
  4. #include "precomp.h"
  5. /* R E F C O U N T */
  6. /*-------------------------------------------------------------------------
  7. %%Function: RefCount
  8. -------------------------------------------------------------------------*/
  9. RefCount::RefCount(void)
  10. {
  11. m_ulcRef = 1;
  12. TRACE_OUT(("Ref: %08X c=%d (created)", this, m_ulcRef));
  13. ASSERT(IS_VALID_STRUCT_PTR(this, CRefCount));
  14. #ifdef DEBUG
  15. m_fTrack = FALSE;
  16. #endif
  17. }
  18. RefCount::~RefCount(void)
  19. {
  20. ASSERT(IS_VALID_STRUCT_PTR(this, CRefCount));
  21. // m_ulcRef may be any value.
  22. TRACE_OUT(("Ref: %08X c=%d (destroyed)", this, m_ulcRef));
  23. ASSERT(IS_VALID_STRUCT_PTR(this, CRefCount));
  24. }
  25. ULONG STDMETHODCALLTYPE RefCount::AddRef(void)
  26. {
  27. ASSERT(IS_VALID_STRUCT_PTR(this, CRefCount));
  28. ASSERT(m_ulcRef < ULONG_MAX);
  29. m_ulcRef++;
  30. TRACE_OUT(("Ref: %08X c=%d (AddRef)", this, m_ulcRef));
  31. ASSERT(IS_VALID_STRUCT_PTR(this, CRefCount));
  32. #ifdef DEBUG
  33. if (m_fTrack)
  34. {
  35. TRACE_OUT(("Obj: %08X c=%d (AddRef) *** Tracking", this, m_ulcRef));
  36. }
  37. #endif
  38. return m_ulcRef;
  39. }
  40. ULONG STDMETHODCALLTYPE RefCount::Release(void)
  41. {
  42. ASSERT(IS_VALID_STRUCT_PTR(this, CRefCount));
  43. if (m_ulcRef > 0)
  44. {
  45. m_ulcRef--;
  46. }
  47. #ifdef DEBUG
  48. if (m_fTrack)
  49. {
  50. TRACE_OUT(("Obj: %08X c=%d (Release) *** Tracking", this, m_ulcRef));
  51. }
  52. #endif
  53. ULONG ulcRef = m_ulcRef;
  54. TRACE_OUT(("Ref: %08X c=%d (Release)", this, m_ulcRef));
  55. if (! ulcRef)
  56. {
  57. delete this;
  58. }
  59. return ulcRef;
  60. }