* Added optional tracing support which can be very useful when debugging

reference count problems.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38866 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2010-10-01 06:49:24 +00:00
parent a633251fba
commit d32f94f43c
1 changed files with 16 additions and 2 deletions

View File

@ -3,11 +3,22 @@
* Distributed under the terms of the MIT License.
*/
#include <Referenceable.h>
//#define TRACE_REFERENCEABLE
#ifdef TRACE_REFERENCEABLE
# include <tracing.h>
# define TRACE(x, ...) ktrace_printf(x, __VA_ARGS__);
#else
# define TRACE(x, ...)
#endif
BReferenceable::BReferenceable(bool deleteWhenUnreferenced)
: fReferenceCount(1),
:
fReferenceCount(1),
fDeleteWhenUnreferenced(deleteWhenUnreferenced)
{
}
@ -23,6 +34,8 @@ BReferenceable::AcquireReference()
{
if (atomic_add(&fReferenceCount, 1) == 0)
FirstReferenceAcquired();
TRACE("%p: acquire %ld\n", this, fReferenceCount);
}
@ -30,6 +43,7 @@ bool
BReferenceable::ReleaseReference()
{
bool unreferenced = (atomic_add(&fReferenceCount, -1) == 1);
TRACE("%p: release %ld\n", this, fReferenceCount);
if (unreferenced)
LastReferenceReleased();
return unreferenced;