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.

51 lines
907 B

  1. #include "precomp.h"
  2. #include "referenc.h"
  3. REFCOUNT::REFCOUNT() :
  4. NumRefs(0),
  5. bMarkedForDelete(FALSE),
  6. bOnStack(FALSE)
  7. {
  8. }
  9. REFCOUNT::~REFCOUNT()
  10. {
  11. // Objects being destroyed should have no
  12. // outstanding references to them and should
  13. // have been explicitly deleted.
  14. ASSERT(NumRefs == 0);
  15. ASSERT(bOnStack || bMarkedForDelete);
  16. }
  17. DWORD REFCOUNT::AddRef()
  18. {
  19. NumRefs++;
  20. return(NumRefs);
  21. }
  22. DWORD REFCOUNT::Release()
  23. {
  24. ASSERT(NumRefs);
  25. DWORD CurrentNumRefs = --NumRefs; // Save because object may be deleted
  26. if(!CurrentNumRefs) {
  27. if(bMarkedForDelete) {
  28. if (!bOnStack) {
  29. delete this;
  30. }
  31. }
  32. }
  33. return CurrentNumRefs;
  34. }
  35. DWORD REFCOUNT::Delete()
  36. {
  37. DWORD CurrentNumRefs = NumRefs; // Save because object may be deleted
  38. REFERENCE r(this);
  39. bMarkedForDelete = TRUE;
  40. return(CurrentNumRefs);
  41. }