//#define OBJECT_DEBUG
-#ifdef OBJECT_DEBUG
- #include <lib/base/eerror.h>
-#endif
+#include <lib/base/eerror.h>
typedef int RESULT;
volatile int count;
oRefCount(): count(0) { }
operator volatile int&() { return count; }
- ~oRefCount() {
+ ~oRefCount()
+ {
#ifdef OBJECT_DEBUG
- if (count) eDebug("OBJECT_DEBUG FATAL: %p has %d references!", this, count); else eDebug("OBJECT_DEBUG refcount ok! (%p)", this);
+ if (count)
+ eDebug("OBJECT_DEBUG FATAL: %p has %d references!", this, count);
+ else
+ eDebug("OBJECT_DEBUG refcount ok! (%p)", this);
#endif
}
};
if (!ref) \
delete this; \
}
- #elif defined(__ppc__)
+ #elif defined(__ppc__) || defined(__powerpc__)
#define DECLARE_REF(x) \
private: oRefCount ref; \
public: void AddRef(); \
if (!ref) \
delete this; \
}
+ #elif defined(__i386__)
+ #define DECLARE_REF(x) \
+ private: oRefCount ref; \
+ public: void AddRef(); \
+ void Release();
+ #define DEFINE_REF(c) \
+ void c::AddRef() \
+ { \
+ __asm__ __volatile__( \
+ " lock ; incl %0 \n" \
+ : "=m" (ref.count) \
+ : "m" (ref.count); \
+ } \
+ void c::Release() \
+ { \
+ __asm__ __volatile__( \
+ " lock ; decl %0 \n" \
+ : "=m" (ref.count) \
+ : "m" (ref.count); \
+ if (!ref) \
+ delete this; \
+ }
#else
+ #warning use non optimized implementation of refcounting.
#define DECLARE_REF(x) \
private:oRefCount ref; \
eSingleLock ref_lock; \