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.

70 lines
1.3 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. RefObj.hxx
  5. Abstract:
  6. Generic base class for reference counted objects.
  7. Author:
  8. Mario Goertzel [MarioGo]
  9. Revision History:
  10. MarioGo 12-15-95 Bits in the 'ol bucket
  11. --*/
  12. #ifndef __REFERENCED_OBJECTS_HXX
  13. #define __REFERENCED_OBJECTS_HXX
  14. class CReferencedObject
  15. {
  16. public:
  17. CReferencedObject() : _references(1) { }
  18. virtual ~CReferencedObject() { ASSERT(_references == 0); }
  19. virtual void Reference()
  20. {
  21. ASSERT(_references >= 0);
  22. _references++;
  23. }
  24. virtual DWORD Release()
  25. {
  26. if ( 0 == Dereference())
  27. {
  28. delete this;
  29. return(0);
  30. }
  31. // this pointer maybe invalid here.
  32. return(1);
  33. }
  34. LONG Dereference()
  35. // Used for objects which override Release().
  36. {
  37. ASSERT(_references);
  38. return(_references--);
  39. }
  40. DWORD References()
  41. {
  42. // Must be called an exclusive lock held or it is meaningless.
  43. ASSERT(_references >= 0);
  44. return(_references);
  45. }
  46. private:
  47. CInterlockedInteger _references;
  48. };
  49. #endif // __REFERENCED_OBJECTS_HXX