summaryrefslogtreecommitdiff
path: root/support
diff options
context:
space:
mode:
authorMiao Wang <miaowang@google.com>2016-05-11 21:49:28 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-05-11 21:49:28 +0000
commit867e3ea533413cc03fbb287641d3c43833b6797d (patch)
tree37022a96fcc53f915a82b211ee594a91b70a5758 /support
parent26e769df4464efe5855588a8c9631d4617501374 (diff)
parent86c79549bfce422e6c521de1a5034be73b194eb9 (diff)
downloadrs-867e3ea533413cc03fbb287641d3c43833b6797d.tar.gz
Merge "[RenderScript] Add finalizer to support lib context." into nyc-dev am: c74fb3fcc1 am: 6725c2872c
am: 32a73a9a3f * commit '32a73a9a3f2d9ddb4bdb4ba9d4bd805596e18509': [RenderScript] Add finalizer to support lib context. Change-Id: I3b19f1084ab43f12513078aca949dd045eb73955
Diffstat (limited to 'support')
-rw-r--r--support/java/src/android/support/v8/renderscript/RenderScript.java76
1 files changed, 50 insertions, 26 deletions
diff --git a/support/java/src/android/support/v8/renderscript/RenderScript.java b/support/java/src/android/support/v8/renderscript/RenderScript.java
index 6cfa49d5..afd09243 100644
--- a/support/java/src/android/support/v8/renderscript/RenderScript.java
+++ b/support/java/src/android/support/v8/renderscript/RenderScript.java
@@ -1045,6 +1045,7 @@ public class RenderScript {
}
long mContext;
+ private boolean mDestroyed = false;
//Dummy device & context for Inc Support Lib
long mIncCon;
//indicator of whether inc support lib has been loaded or not.
@@ -1655,6 +1656,54 @@ public class RenderScript {
nContextFinish();
}
+ private void helpDestroy() {
+ boolean shouldDestroy = false;
+ synchronized(this) {
+ if (!mDestroyed) {
+ shouldDestroy = true;
+ mDestroyed = true;
+ }
+ }
+
+ if (shouldDestroy) {
+ nContextFinish();
+ if (mIncCon != 0) {
+ nIncContextFinish();
+ nIncContextDestroy();
+ mIncCon = 0;
+ }
+ nContextDeinitToClient(mContext);
+ mMessageThread.mRun = false;
+ // Interrupt mMessageThread so it gets to see immediately that mRun is false
+ // and exit rightaway.
+ mMessageThread.interrupt();
+
+ // Wait for mMessageThread to join. Try in a loop, in case this thread gets interrupted
+ // during the wait. If interrupted, set the "interrupted" status of the current thread.
+ boolean hasJoined = false, interrupted = false;
+ while (!hasJoined) {
+ try {
+ mMessageThread.join();
+ hasJoined = true;
+ } catch (InterruptedException e) {
+ interrupted = true;
+ }
+ }
+ if (interrupted) {
+ Log.v(LOG_TAG, "Interrupted during wait for MessageThread to join");
+ Thread.currentThread().interrupt();
+ }
+
+ nContextDestroy();
+ }
+ }
+
+ @Override
+ 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
@@ -1670,32 +1719,7 @@ public class RenderScript {
return;
}
validate();
- nContextFinish();
- if (mIncCon != 0) {
- nIncContextFinish();
- nIncContextDestroy();
- mIncCon = 0;
- }
- nContextDeinitToClient(mContext);
- mMessageThread.mRun = false;
-
- // Wait for mMessageThread to join. Try in a loop, in case this thread gets interrupted
- // during the wait. If interrupted, set the "interrupted" status of the current thread.
- boolean hasJoined = false, interrupted = false;
- while (!hasJoined) {
- try {
- mMessageThread.join();
- hasJoined = true;
- } catch (InterruptedException e) {
- interrupted = true;
- }
- }
- if (interrupted) {
- Log.v(LOG_TAG, "Interrupted during wait for MessageThread to join");
- Thread.currentThread().interrupt();
- }
-
- nContextDestroy();
+ helpDestroy();
}
boolean isAlive() {