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,14 +1384,16 @@ public class RenderScript {
|
|||||||
nContextFinish();
|
nContextFinish();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void helpDestroy() {
|
||||||
* Destroys this RenderScript context. Once this function is called,
|
boolean shouldDestroy = false;
|
||||||
* using this context or any objects belonging to this context is
|
synchronized(this) {
|
||||||
* illegal.
|
if (!mDestroyed) {
|
||||||
*
|
shouldDestroy = true;
|
||||||
*/
|
mDestroyed = true;
|
||||||
public void destroy() {
|
}
|
||||||
validate();
|
}
|
||||||
|
|
||||||
|
if (shouldDestroy) {
|
||||||
nContextFinish();
|
nContextFinish();
|
||||||
|
|
||||||
nContextDeinitToClient(mContext);
|
nContextDeinitToClient(mContext);
|
||||||
@@ -1404,6 +1408,24 @@ public class RenderScript {
|
|||||||
nDeviceDestroy(mDev);
|
nDeviceDestroy(mDev);
|
||||||
mDev = 0;
|
mDev = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void finalize() throws Throwable {
|
||||||
|
helpDestroy();
|
||||||
|
super.finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroys this RenderScript context. Once this function is called,
|
||||||
|
* using this context or any objects belonging to this context is
|
||||||
|
* illegal.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void destroy() {
|
||||||
|
validate();
|
||||||
|
helpDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
boolean isAlive() {
|
boolean isAlive() {
|
||||||
return mContext != 0;
|
return mContext != 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user