Restore the interrupted flag after blocking operations

If the main thread was interrupted during
ExoPlayerImplInternal.blockingSendMessage/release, the interrupted flag was
immediately set but then wait() was called on the next iteration. wait() would
immediately throw InterruptedException, causing the main thread to spin until
the blocking operation completed.

Instead of resetting the flag immediately, reset it after the blocking
operation completes.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=165426493
This commit is contained in:
andrewlewis 2017-08-16 04:47:51 -07:00 committed by Oliver Woodman
parent e0b69b8115
commit bbc3b182bb

View File

@ -263,13 +263,18 @@ import java.io.IOException;
} }
int messageNumber = customMessagesSent++; int messageNumber = customMessagesSent++;
handler.obtainMessage(MSG_CUSTOM, messages).sendToTarget(); handler.obtainMessage(MSG_CUSTOM, messages).sendToTarget();
boolean wasInterrupted = false;
while (customMessagesProcessed <= messageNumber) { while (customMessagesProcessed <= messageNumber) {
try { try {
wait(); wait();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); wasInterrupted = true;
} }
} }
if (wasInterrupted) {
// Restore the interrupted status.
Thread.currentThread().interrupt();
}
} }
public synchronized void release() { public synchronized void release() {
@ -277,13 +282,18 @@ import java.io.IOException;
return; return;
} }
handler.sendEmptyMessage(MSG_RELEASE); handler.sendEmptyMessage(MSG_RELEASE);
boolean wasInterrupted = false;
while (!released) { while (!released) {
try { try {
wait(); wait();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); wasInterrupted = true;
} }
} }
if (wasInterrupted) {
// Restore the interrupted status.
Thread.currentThread().interrupt();
}
internalPlaybackThread.quit(); internalPlaybackThread.quit();
} }