1/* 2 * Copyright 2001-2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * DarkWyrm <bpmagic@columbus.rr.com> 7 * Axel Dörfler, axeld@pinc-software.de 8 * Stephan Aßmus <superstippi@gmx.de> 9 */ 10 11#include "Referenceable.h" 12 13#define TRACE 0 14 15#if TRACE 16#define ICON 1 17#include <debugger.h> 18#include <stdio.h> 19 20#if ICON 21#include "IconObject.h" 22#endif 23#endif 24 25// constructor 26Referenceable::Referenceable() 27 : fReferenceCount(1) 28{ 29} 30 31// destructor 32Referenceable::~Referenceable() 33{ 34} 35 36// Acquire 37void 38Referenceable::Acquire() 39{ 40 atomic_add(&fReferenceCount, 1); 41} 42 43// Release 44bool 45Referenceable::Release() 46{ 47#if TRACE 48 int32 old = atomic_add(&fReferenceCount, -1); 49//#if ICON 50// if (old > 1) { 51//IconObject* object = dynamic_cast<IconObject*>(this); 52//printf("Referenceable::Release() - %s: %ld\n", 53// object ? object->Name() : "unkown", fReferenceCount); 54// } else 55//#endif 56 if (old == 1) { 57#if ICON 58IconObject* object = dynamic_cast<IconObject*>(this); 59printf("Referenceable::Release() - deleting %s\n", 60 object ? object->Name() : "unkown"); 61#else 62printf("Referenceable::Release() - deleting\n"); 63#endif 64 delete this; 65 return true; 66 } else if (old < 1) 67 debugger("Referenceable::Release() - already deleted"); 68#else 69 if (atomic_add(&fReferenceCount, -1) == 1) { 70 delete this; 71 return true; 72 } 73#endif 74 75 return false; 76} 77 78