haiku/src/servers/registrar/Referenceable.cpp
Ingo Weinhold 757bc7b934 Renamed Referencable to Referenceable (mainly to make Axel happier :-).
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11035 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-01-25 16:10:03 +00:00

45 lines
779 B
C++

/*
* Copyright 2005, Ingo Weinhold, bonefish@users.sf.net. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include "Debug.h"
#include "Referenceable.h"
// constructor
Referenceable::Referenceable(bool deleteWhenUnreferenced)
: fReferenceCount(1),
fDeleteWhenUnreferenced(deleteWhenUnreferenced)
{
}
// destructor
Referenceable::~Referenceable()
{
}
// AddReference
void
Referenceable::AddReference()
{
atomic_add(&fReferenceCount, 1);
}
// RemoveReference
bool
Referenceable::RemoveReference()
{
bool unreferenced = (atomic_add(&fReferenceCount, -1) == 1);
if (fDeleteWhenUnreferenced && unreferenced)
delete this;
return unreferenced;
}
// CountReferences
int32
Referenceable::CountReferences() const
{
return fReferenceCount;
}