12345678910111213141516171819202122232425262728293031323334353637 |
- #include "ReferenceCounter.h"
- using namespace Framework;
- ReferenceCounter::ReferenceCounter()
- {
- cs = new CRITICAL_SECTION();
- InitializeCriticalSection(cs);
- ref = 1;
- }
- ReferenceCounter::~ReferenceCounter() {
- DeleteCriticalSection(cs);
- delete cs;
- }
- int ReferenceCounter::getReferenceCount() const
- {
- return ref;
- }
- ReferenceCounter* ReferenceCounter::getThis()
- {
- EnterCriticalSection(cs);
- ++ref;
- LeaveCriticalSection(cs);
- return this;
- }
- void* ReferenceCounter::release()
- {
- EnterCriticalSection(cs);
- --ref;
- LeaveCriticalSection(cs);
- if (!ref) delete this;
- return 0;
- }
|