Merge "Safely handle interrupts during Thread.join()"

This commit is contained in:
Pirama Arumuga Nainar
2015-10-05 23:27:10 +00:00
committed by Gerrit Code Review

View File

@@ -1576,15 +1576,20 @@ public class RenderScript {
mMessageThread.mRun = false; mMessageThread.mRun = false;
// Wait for mMessageThread to join. Try in a loop, in case this thread gets interrupted // Wait for mMessageThread to join. Try in a loop, in case this thread gets interrupted
// during the wait. // during the wait. If interrupted, set the "interrupted" status of the current thread.
boolean hasJoined = false; boolean hasJoined = false, interrupted = false;
while (!hasJoined) { while (!hasJoined) {
try { try {
mMessageThread.join(); mMessageThread.join();
hasJoined = true; hasJoined = true;
} catch (InterruptedException e) { } catch (InterruptedException e) {
interrupted = true;
} }
} }
if (interrupted) {
Log.v(LOG_TAG, "Interrupted during wait for MessageThread to join");
Thread.currentThread().interrupt();
}
nContextDestroy(); nContextDestroy();