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.

72 lines
994 B

  1. /*
  2. * refcount.cpp - RefCount class implementation.
  3. */
  4. /* Headers
  5. **********/
  6. #include "project.hpp" // for ULONG_MAX...
  7. #include "refcount.hpp"
  8. extern ULONG DllAddRef(void);
  9. extern ULONG DllRelease(void);
  10. /********************************** Methods **********************************/
  11. RefCount::RefCount(void)
  12. {
  13. // Don't validate this until after initialization.
  14. m_ulcRef = 1;
  15. DllAddRef();
  16. return;
  17. }
  18. RefCount::~RefCount(void)
  19. {
  20. // m_ulcRef may be any value.
  21. DllRelease();
  22. return;
  23. }
  24. ULONG STDMETHODCALLTYPE RefCount::AddRef(void)
  25. {
  26. ULONG ulRet = 0;
  27. // this is really bad... returns an error of some kind
  28. if(m_ulcRef >= ULONG_MAX)
  29. {
  30. ulRet = 0;
  31. goto exit;
  32. }
  33. m_ulcRef++;
  34. ulRet = m_ulcRef;
  35. exit:
  36. return(ulRet);
  37. }
  38. ULONG STDMETHODCALLTYPE RefCount::Release(void)
  39. {
  40. ULONG ulcRef;
  41. if (m_ulcRef > 0)
  42. m_ulcRef--;
  43. ulcRef = m_ulcRef;
  44. if (! ulcRef)
  45. delete this;
  46. return(ulcRef);
  47. }