+ struct oRefCount
+ {
+ volatile int count;
+ oRefCount(): count(0) { }
+ operator volatile int&() { return count; }
+ ~oRefCount()
+ {
+ #ifdef OBJECT_DEBUG
+ if (count)
+ eDebug("OBJECT_DEBUG FATAL: %p has %d references!", this, count);
+ else
+ eDebug("OBJECT_DEBUG refcount ok! (%p)", this);
+ #endif
+ }
+ };
+
+ #if defined(OBJECT_DEBUG)
+ extern int object_total_remaining;
+ #define DECLARE_REF(x) \
+ private:oRefCount ref; \
+ eSingleLock ref_lock; \
+ public: void AddRef(); \
+ void Release();
+ #define DEFINE_REF(c) \
+ void c::AddRef() \
+ { \
+ eSingleLocker l(ref_lock); \
+ ++object_total_remaining; \
+ ++ref; \
+ eDebug("OBJECT_DEBUG " #c "+%p now %d", this, (int)ref); \
+ } \
+ void c::Release() \
+ { \
+ { \
+ eSingleLocker l(ref_lock); \
+ --object_total_remaining; \
+ --ref; \
+ eDebug("OBJECT_DEBUG " #c "-%p now %d", this, (int)ref); \
+ } \
+ if (!ref) \
+ delete this; \
+ }
+ #elif defined(__mips__)