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.

104 lines
1.6 KiB

  1. /*
  2. * refcount.cpp - RefCount class implementation.
  3. */
  4. /* Headers
  5. **********/
  6. #include "project.hpp"
  7. #pragma hdrstop
  8. #include "clsfact.h"
  9. /****************************** Public Functions *****************************/
  10. #ifdef DEBUG
  11. PUBLIC_CODE BOOL IsValidPCRefCount(PCRefCount pcrefcnt)
  12. {
  13. // m_ulcRef may be any value.
  14. return(IS_VALID_READ_PTR(pcrefcnt, CRefCount));
  15. }
  16. #endif
  17. /********************************** Methods **********************************/
  18. RefCount::RefCount(void)
  19. {
  20. DebugEntry(RefCount::RefCount);
  21. /* Don't validate this until after initialization. */
  22. m_ulcRef = 1;
  23. DLLAddRef();
  24. ASSERT(IS_VALID_STRUCT_PTR(this, CRefCount));
  25. DebugExitVOID(RefCount::RefCount);
  26. return;
  27. }
  28. RefCount::~RefCount(void)
  29. {
  30. DebugEntry(RefCount::~RefCount);
  31. ASSERT(IS_VALID_STRUCT_PTR(this, CRefCount));
  32. // m_ulcRef may be any value.
  33. DLLRelease();
  34. ASSERT(IS_VALID_STRUCT_PTR(this, CRefCount));
  35. DebugExitVOID(RefCount::~RefCount);
  36. return;
  37. }
  38. ULONG STDMETHODCALLTYPE RefCount::AddRef(void)
  39. {
  40. DebugEntry(RefCount::AddRef);
  41. ASSERT(IS_VALID_STRUCT_PTR(this, CRefCount));
  42. ASSERT(m_ulcRef < ULONG_MAX);
  43. m_ulcRef++;
  44. ASSERT(IS_VALID_STRUCT_PTR(this, CRefCount));
  45. DebugExitULONG(RefCount::AddRef, m_ulcRef);
  46. return(m_ulcRef);
  47. }
  48. ULONG STDMETHODCALLTYPE RefCount::Release(void)
  49. {
  50. ULONG ulcRef;
  51. DebugEntry(RefCount::Release);
  52. ASSERT(IS_VALID_STRUCT_PTR(this, CRefCount));
  53. if (EVAL(m_ulcRef > 0))
  54. m_ulcRef--;
  55. ulcRef = m_ulcRef;
  56. if (! ulcRef)
  57. delete this;
  58. DebugExitULONG(RefCount::Release, ulcRef);
  59. return(ulcRef);
  60. }