am adb52ef7: Merge "Implement finalizer for RS contexts."
* commit 'adb52ef7034d4d3e0eee58cedae2a343d29771b9': Implement finalizer for RS contexts.
This commit is contained in:
@@ -938,6 +938,8 @@ public class RenderScript {
|
|||||||
|
|
||||||
long mDev;
|
long mDev;
|
||||||
long mContext;
|
long mContext;
|
||||||
|
private boolean mDestroyed = false;
|
||||||
|
|
||||||
@SuppressWarnings({"FieldCanBeLocal"})
|
@SuppressWarnings({"FieldCanBeLocal"})
|
||||||
MessageThread mMessageThread;
|
MessageThread mMessageThread;
|
||||||
|
|
||||||
@@ -1382,6 +1384,38 @@ public class RenderScript {
|
|||||||
nContextFinish();
|
nContextFinish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void helpDestroy() {
|
||||||
|
boolean shouldDestroy = false;
|
||||||
|
synchronized(this) {
|
||||||
|
if (!mDestroyed) {
|
||||||
|
shouldDestroy = true;
|
||||||
|
mDestroyed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldDestroy) {
|
||||||
|
nContextFinish();
|
||||||
|
|
||||||
|
nContextDeinitToClient(mContext);
|
||||||
|
mMessageThread.mRun = false;
|
||||||
|
try {
|
||||||
|
mMessageThread.join();
|
||||||
|
} catch(InterruptedException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
nContextDestroy();
|
||||||
|
|
||||||
|
nDeviceDestroy(mDev);
|
||||||
|
mDev = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void finalize() throws Throwable {
|
||||||
|
helpDestroy();
|
||||||
|
super.finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroys this RenderScript context. Once this function is called,
|
* Destroys this RenderScript context. Once this function is called,
|
||||||
* using this context or any objects belonging to this context is
|
* using this context or any objects belonging to this context is
|
||||||
@@ -1390,19 +1424,7 @@ public class RenderScript {
|
|||||||
*/
|
*/
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
validate();
|
validate();
|
||||||
nContextFinish();
|
helpDestroy();
|
||||||
|
|
||||||
nContextDeinitToClient(mContext);
|
|
||||||
mMessageThread.mRun = false;
|
|
||||||
try {
|
|
||||||
mMessageThread.join();
|
|
||||||
} catch(InterruptedException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
nContextDestroy();
|
|
||||||
|
|
||||||
nDeviceDestroy(mDev);
|
|
||||||
mDev = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isAlive() {
|
boolean isAlive() {
|
||||||
|
|||||||
Reference in New Issue
Block a user