1 #ifndef __base_object_h
2 #define __base_object_h
5 #include <lib/base/smartptr.h>
6 #include <lib/base/elock.h>
11 #include <lib/base/eerror.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(): count(0) { }
33 operator volatile int&() { return count; }
36 if (count) eDebug("OBJECT_DEBUG FATAL: %p has %d references!", this, count); else eDebug("OBJECT_DEBUG refcount ok! (%p)", this);
41 #if defined(OBJECT_DEBUG)
42 extern int object_total_remaining;
43 #define DECLARE_REF(x) \
44 private:oRefCount ref; \
45 eSingleLock ref_lock; \
46 public: void AddRef(); \
48 #define DEFINE_REF(c) \
51 eSingleLocker l(ref_lock); \
52 ++object_total_remaining; \
54 eDebug("OBJECT_DEBUG " #c "+%p now %d", this, (int)ref); \
59 eSingleLocker l(ref_lock); \
60 --object_total_remaining; \
62 eDebug("OBJECT_DEBUG " #c "-%p now %d", this, (int)ref); \
67 #elif defined(__mips__)
68 #define DECLARE_REF(x) \
69 private: oRefCount ref; \
70 public: void AddRef(); \
72 #define DEFINE_REF(c) \
76 __asm__ __volatile__( \
78 "1: ll %0, %1 # load counter \n" \
80 " addu %0, 1 # increment \n" \
82 " sc %0, %1 # try to store, checking for atomicity \n" \
84 " beqz %0, 1b # if not atomic (0), try again \n" \
85 : "=&r" (temp), "=m" (ref.count) \
92 __asm__ __volatile__( \
96 " subu %0, 1 # decrement \n" \
101 : "=&r" (temp), "=m" (ref.count) \
107 #elif defined(__ppc__)
108 #define DECLARE_REF(x) \
109 private: oRefCount ref; \
110 public: void AddRef(); \
112 #define DEFINE_REF(c) \
116 __asm__ __volatile__( \
117 "1: lwarx %0, 0, %3 \n" \
118 " add %0, %2, %0 \n" \
119 " dcbt 0, %3 # workaround for PPC405CR Errata\n" \
120 " stwcx. %0, 0, %3 \n" \
122 : "=&r" (temp), "=m" (ref.count) \
123 : "r" (1), "r" (&ref.count), "m" (ref.count) \
129 __asm__ __volatile__( \
130 "1: lwarx %0, 0, %3 \n" \
131 " subf %0, %2, %0 \n" \
132 " dcbt 0, %3 # workaround for PPC405CR Errata\n" \
133 " stwcx. %0, 0, %3 \n" \
135 : "=&r" (temp), "=m" (ref.count) \
136 : "r" (1), "r" (&ref.count), "m" (ref.count) \
142 #define DECLARE_REF(x) \
143 private:oRefCount ref; \
144 eSingleLock ref_lock; \
145 public: void AddRef(); \
147 #define DEFINE_REF(c) \
150 eSingleLocker l(ref_lock); \
156 eSingleLocker l(ref_lock); \
164 #define DECLARE_REF(x) \
173 #endif // __base_object_h