summaryrefslogtreecommitdiffstats
path: root/libs/rs/rsObjectBase.h
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2010-10-21 14:06:55 -0700
committerJason Sams <rjsams@android.com>2010-10-21 21:17:30 -0700
commitb38d534873ca514f5a5230596c838aa37eca1568 (patch)
tree4473cccf239e0a97597db92052508b2149309ad1 /libs/rs/rsObjectBase.h
parent4924aee9cb1c5988359f3162b6e89689c5b101e1 (diff)
downloadframeworks_base-b38d534873ca514f5a5230596c838aa37eca1568.zip
frameworks_base-b38d534873ca514f5a5230596c838aa37eca1568.tar.gz
frameworks_base-b38d534873ca514f5a5230596c838aa37eca1568.tar.bz2
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
Diffstat (limited to 'libs/rs/rsObjectBase.h')
-rw-r--r--libs/rs/rsObjectBase.h33
1 files changed, 25 insertions, 8 deletions
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 <utils/CallStack.h>
+#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<class T>
@@ -104,6 +117,10 @@ public:
}
}
+ ObjectBaseRef & operator= (const ObjectBaseRef &ref) {
+ return ObjectBaseRef(ref);
+ }
+
~ObjectBaseRef() {
clear();
}