1 #ifndef __base_object_h
2 #define __base_object_h
6 // #define OBJECT_DEBUG
8 #include <lib/base/smartptr.h>
10 #include <lib/base/eerror.h>
12 #include <lib/base/elock.h>
19 /* we don't allow the default operator here, as it would break the refcount. */
20 void operator=(const iObject &);
22 virtual ~iObject() { }
24 virtual void AddRef()=0;
25 virtual void Release()=0;
32 oRefCount(): ref(0) { }
33 operator int&() { return ref; }
36 if (ref) eDebug("OBJECT_DEBUG FATAL: %p has %d references!", this, ref); else eDebug("OBJECT_DEBUG refcount ok! (%p)", this);
43 #define DECLARE_REF(x) \
44 private: oRefCount ref; \
45 public: void AddRef(); \
47 #define DEFINE_REF(c) \
51 __asm__ __volatile__( \
53 "1: ll %0, %1 # load counter \n" \
55 " addu %0, 1 # increment \n" \
57 " sc %0, %1 # try to store, checking for atomicity \n" \
59 " beqz %0, 1b # if not atomic (0), try again \n" \
60 : "=&r" (temp), "=m" ((int)ref) \
67 __asm__ __volatile__( \
71 " subu %0, 1 # decrement \n" \
76 : "=&r" (temp), "=m" ((int)ref) \
82 #elif defined(__ppc__)
83 #define DECLARE_REF(x) \
84 private: oRefCount ref; \
85 public: void AddRef(); \
87 #define DEFINE_REF(c) \
91 __asm__ __volatile__( \
92 "1: lwarx %0, 0, %3 \n" \
93 " add %0, %2, %0 \n" \
95 " stwcx. %0, 0, %3 \n" \
97 : "=&r" (temp), "=m" ((int)ref) \
98 : "r" (1), "r" (&((int)ref)), "m" ((int)ref) \
104 __asm__ __volatile__( \
105 "1: lwarx %0, 0, %3 \n" \
106 " subf %0, %2, %0 \n" \
108 " stwcx. %0, 0, %3 \n" \
110 : "=&r" (temp), "=m" ((int)ref) \
111 : "r" (1), "r" (&((int)ref)), "m" ((int)ref) \
117 #define DECLARE_REF(x) \
118 private:oRefCount ref; \
119 eSingleLock ref_lock; \
120 public: void AddRef(); \
123 extern int object_total_remaining;
124 #define DEFINE_REF(c) \
127 eSingleLocker l(ref_lock); \
128 ++object_total_remaining; \
130 eDebug("OBJECT_DEBUG " #c "+%p now %d", this, (int)ref); \
135 eSingleLocker l(ref_lock); \
136 --object_total_remaining; \
138 eDebug("OBJECT_DEBUG " #c "-%p now %d", this, ref); \
143 #error fix locking for debug
145 #define DEFINE_REF(c) \
148 eSingleLocker l(ref_lock); \
154 eSingleLocker l(ref_lock); \
163 #define DECLARE_REF(x) \