WindowsXP/Source/XPSP1/NT/enduser/netmeeting/nmutil/referenc.cpp
2024-08-03 16:30:48 +02:00

52 lines
856 B
C++

#include "precomp.h"
#include "referenc.h"
REFCOUNT::REFCOUNT() :
NumRefs(0),
bMarkedForDelete(FALSE),
bOnStack(FALSE)
{
}
REFCOUNT::~REFCOUNT()
{
// Objects being destroyed should have no
// outstanding references to them and should
// have been explicitly deleted.
ASSERT(NumRefs == 0);
ASSERT(bOnStack || bMarkedForDelete);
}
DWORD REFCOUNT::AddRef()
{
NumRefs++;
return(NumRefs);
}
DWORD REFCOUNT::Release()
{
ASSERT(NumRefs);
DWORD CurrentNumRefs = --NumRefs; // Save because object may be deleted
if(!CurrentNumRefs) {
if(bMarkedForDelete) {
if (!bOnStack) {
delete this;
}
}
}
return CurrentNumRefs;
}
DWORD REFCOUNT::Delete()
{
DWORD CurrentNumRefs = NumRefs; // Save because object may be deleted
REFERENCE r(this);
bMarkedForDelete = TRUE;
return(CurrentNumRefs);
}