2851dbad53
private/shared. * Made AddReference() and CountReferences() inlines. * The registrar is now using the private Referenceable version in libbe.so. * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21767 a95241bf-73f2-0310-859d-f6bbb57e9c96
31 lines
581 B
C++
31 lines
581 B
C++
/*
|
|
* Copyright 2005-2007, Ingo Weinhold, bonefish@users.sf.net. All rights reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
|
|
|
|
#include <Referenceable.h>
|
|
|
|
|
|
// constructor
|
|
Referenceable::Referenceable(bool deleteWhenUnreferenced)
|
|
: fReferenceCount(1),
|
|
fDeleteWhenUnreferenced(deleteWhenUnreferenced)
|
|
{
|
|
}
|
|
|
|
// destructor
|
|
Referenceable::~Referenceable()
|
|
{
|
|
}
|
|
|
|
// RemoveReference
|
|
bool
|
|
Referenceable::RemoveReference()
|
|
{
|
|
bool unreferenced = (atomic_add(&fReferenceCount, -1) == 1);
|
|
if (fDeleteWhenUnreferenced && unreferenced)
|
|
delete this;
|
|
return unreferenced;
|
|
}
|