* 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:
parent
a633251fba
commit
d32f94f43c
@ -3,12 +3,23 @@
|
||||
* 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),
|
||||
fDeleteWhenUnreferenced(deleteWhenUnreferenced)
|
||||
:
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user