ReferenceCounter.cpp 628 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "ReferenceCounter.h"
  2. using namespace Framework;
  3. ReferenceCounter::ReferenceCounter()
  4. {
  5. cs = new CRITICAL_SECTION();
  6. InitializeCriticalSection(cs);
  7. ref = 1;
  8. }
  9. ReferenceCounter::~ReferenceCounter() {
  10. DeleteCriticalSection(cs);
  11. delete cs;
  12. }
  13. int ReferenceCounter::getReferenceCount() const
  14. {
  15. return ref;
  16. }
  17. ReferenceCounter* ReferenceCounter::getThis()
  18. {
  19. EnterCriticalSection(cs);
  20. ++ref;
  21. LeaveCriticalSection(cs);
  22. return this;
  23. }
  24. void* ReferenceCounter::release()
  25. {
  26. EnterCriticalSection(cs);
  27. --ref;
  28. LeaveCriticalSection(cs);
  29. if (!ref) delete this;
  30. return 0;
  31. }