From b38d534873ca514f5a5230596c838aa37eca1568 Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Thu, 21 Oct 2010 14:06:55 -0700 Subject: Fix refcounting bugs where the sys refcount could be corrupted during async type creation. Change-Id: If42828e92990598b0cb5da81c82ea513f94725f2 Fix stack object deletion bug. Change-Id: I2c723aa5ad15e0c99dc9cd0cfbc7db80bace172a --- libs/rs/rsObjectBase.h | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'libs/rs/rsObjectBase.h') diff --git a/libs/rs/rsObjectBase.h b/libs/rs/rsObjectBase.h index 8d1ace1..5f03db5 100644 --- a/libs/rs/rsObjectBase.h +++ b/libs/rs/rsObjectBase.h @@ -19,6 +19,11 @@ #include "rsUtils.h" +#define RS_OBJECT_DEBUG 0 + +#if RS_OBJECT_DEBUG + #include +#endif namespace android { namespace renderscript { @@ -31,7 +36,6 @@ class ObjectBase { public: ObjectBase(Context *rsc); - virtual ~ObjectBase(); void incSysRef() const; bool decSysRef() const; @@ -39,7 +43,8 @@ public: void incUserRef() const; bool decUserRef() const; bool zeroUserRef() const; - void prelockedIncUserRef() const; + + static bool checkDelete(const ObjectBase *); const char * getName() const { return mName.string(); @@ -58,13 +63,18 @@ public: static bool isValid(const Context *rsc, const ObjectBase *obj); - static void lockUserRef(); - static void unlockUserRef(); + // The async lock is taken during object creation in non-rs threads + // and object deletion in the rs thread. + static void asyncLock(); + static void asyncUnlock(); protected: - const char *mAllocFile; - uint32_t mAllocLine; + // Called inside the async lock for any object list management that is + // necessary in derived classes. + virtual void preDestroy() const; + Context *mRSC; + virtual ~ObjectBase(); private: static pthread_mutex_t gObjectInitMutex; @@ -72,14 +82,17 @@ private: void add() const; void remove() const; - bool checkDelete() const; - String8 mName; mutable int32_t mSysRefCount; mutable int32_t mUserRefCount; mutable const ObjectBase * mPrev; mutable const ObjectBase * mNext; + +#if RS_OBJECT_DEBUG + CallStack mStack; +#endif + }; template @@ -104,6 +117,10 @@ public: } } + ObjectBaseRef & operator= (const ObjectBaseRef &ref) { + return ObjectBaseRef(ref); + } + ~ObjectBaseRef() { clear(); } -- cgit v1.1