Fix teardown bug found in books.
Change-Id: I9ac449b644108148b331e0c552f289bf80a07f7e
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index 021ff92..a5810d4 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -47,7 +47,7 @@
param int32_t priority
}
-ContextDestroy {
+ContextDestroyWorker {
}
AssignName {
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index 77e80320..ec1f684 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -135,7 +135,6 @@
}
void Allocation::freeScriptMemory() {
- rsAssert(!(mUsageFlags & RS_ALLOCATION_USAGE_SCRIPT));
if (mPtr) {
free(mPtr);
mPtr = NULL;
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 2988950..22c73fe 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -509,20 +509,6 @@
}
LOGV("%p, RS Thread exiting", rsc);
- if (rsc->mIsGraphicsContext) {
- rsc->mRaster.clear();
- rsc->mFragment.clear();
- rsc->mVertex.clear();
- rsc->mFragmentStore.clear();
- rsc->mFont.clear();
- rsc->mRootScript.clear();
- rsc->mStateRaster.deinit(rsc);
- rsc->mStateVertex.deinit(rsc);
- rsc->mStateFragment.deinit(rsc);
- rsc->mStateFragmentStore.deinit(rsc);
- rsc->mStateFont.deinit(rsc);
- }
- ObjectBase::zeroAllUserRef(rsc);
if (rsc->mIsGraphicsContext) {
pthread_mutex_lock(&gInitMutex);
@@ -535,6 +521,25 @@
return NULL;
}
+void Context::destroyWorkerThreadResources() {
+ LOGV("destroyWorkerThreadResources 1");
+ if (mIsGraphicsContext) {
+ mRaster.clear();
+ mFragment.clear();
+ mVertex.clear();
+ mFragmentStore.clear();
+ mFont.clear();
+ mRootScript.clear();
+ mStateRaster.deinit(this);
+ mStateVertex.deinit(this);
+ mStateFragment.deinit(this);
+ mStateFragmentStore.deinit(this);
+ mStateFont.deinit(this);
+ }
+ ObjectBase::zeroAllUserRef(this);
+ LOGV("destroyWorkerThreadResources 2");
+}
+
void * Context::helperThreadProc(void *vrsc) {
Context *rsc = static_cast<Context *>(vrsc);
uint32_t idx = (uint32_t)android_atomic_inc(&rsc->mWorkers.mLaunchCount);
@@ -725,6 +730,7 @@
mDev = NULL;
}
pthread_mutex_unlock(&gInitMutex);
+ LOGV("Context::~Context done");
}
void Context::setSurface(uint32_t w, uint32_t h, ANativeWindow *sur) {
@@ -1019,14 +1025,23 @@
ObjectBase::dumpAll(rsc);
}
-void rsi_ContextDestroy(Context *rsc) {
+void rsi_ContextDestroyWorker(Context *rsc) {
+ LOGE("rsi_ContextDestroyWorker 1");
+ rsc->destroyWorkerThreadResources();;
+ LOGE("rsi_ContextDestroyWorker 2");
+}
+
+}
+}
+
+void rsContextDestroy(RsContext vcon) {
+ LOGV("rsContextDestroy %p", vcon);
+ Context *rsc = static_cast<Context *>(vcon);
+ rsContextDestroyWorker(rsc);
delete rsc;
+ LOGV("rsContextDestroy 2 %p", vcon);
}
-}
-}
-
-
RsContext rsContextCreate(RsDevice vdev, uint32_t version) {
LOGV("rsContextCreate %p", vdev);
Device * dev = static_cast<Device *>(vdev);
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index 49ee676..3c402c4 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -137,6 +137,7 @@
void resume();
void setSurface(uint32_t w, uint32_t h, ANativeWindow *sur);
void setPriority(int32_t p);
+ void destroyWorkerThreadResources();
void assignName(ObjectBase *obj, const char *name, uint32_t len);
void removeName(ObjectBase *obj);
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index 64eb7d2..ef06033 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -37,13 +37,13 @@
ScriptC::ScriptC(Context *rsc) : Script(rsc) {
- LOGD(">>>> ScriptC ctor called, obj=%x", this);
+ LOGD(">>>> ScriptC ctor called, obj=%p", this);
mBccScript = NULL;
memset(&mProgram, 0, sizeof(mProgram));
}
ScriptC::~ScriptC() {
- LOGD(">>>> ~ScriptC()");
+ LOGD(">>>> ~ScriptC() mBccScript = %p", mBccScript);
if (mBccScript) {
bccDeleteScript(mBccScript);
LOGD(">>>> ~ScriptC(mBCCScript)");