haiku/src/kits/support/Referenceable.cpp
Axel Dörfler 2851dbad53 * Moved Referenceable.cpp to src/kits/support (private libbe API), and its header to
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
2007-07-31 16:20:37 +00:00

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;
}