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.

55 lines
1.2 KiB

  1. // RCObject.cpp -- Reference counted abstract base class
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  3. // 1999. This computer program includes Confidential, Proprietary
  4. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  5. // use, disclosure, and/or reproduction is prohibited unless authorized
  6. // in writing. All Rights Reserved.
  7. #include <stdexcept> // for over/under flow
  8. #include "windows.h"
  9. #include "winbase.h"
  10. #include "slbRCObj.h"
  11. using namespace std;
  12. using namespace slbRefCnt;
  13. void
  14. RCObject::AddReference()
  15. {
  16. // guard against overflow
  17. if (0 > InterlockedIncrement(&m_cRefCount))
  18. throw std::overflow_error("SLB: Reference Count overflow");
  19. }
  20. void
  21. RCObject::RemoveReference()
  22. {
  23. LONG count = InterlockedDecrement(&m_cRefCount);
  24. if (0 > count)
  25. throw std::overflow_error("SLB: Reference Count underflow");
  26. if (0 == count)
  27. delete this;
  28. }
  29. RCObject::RCObject()
  30. : m_cRefCount(0)
  31. {
  32. }
  33. RCObject::RCObject(RCObject const&)
  34. : m_cRefCount(0)
  35. {
  36. }
  37. RCObject::~RCObject()
  38. {
  39. }
  40. RCObject &
  41. RCObject::operator=(RCObject const&)
  42. {
  43. return *this;
  44. }