From bbc3b182bbd3bdfeeeb758c67d030b7e73e52615 Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Wed, 16 Aug 2017 04:47:51 -0700 Subject: [PATCH] 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 --- .../android/exoplayer2/ExoPlayerImplInternal.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java index a789dbc1b2..b8274126b5 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java @@ -263,13 +263,18 @@ import java.io.IOException; } int messageNumber = customMessagesSent++; handler.obtainMessage(MSG_CUSTOM, messages).sendToTarget(); + boolean wasInterrupted = false; while (customMessagesProcessed <= messageNumber) { try { wait(); } catch (InterruptedException e) { - Thread.currentThread().interrupt(); + wasInterrupted = true; } } + if (wasInterrupted) { + // Restore the interrupted status. + Thread.currentThread().interrupt(); + } } public synchronized void release() { @@ -277,13 +282,18 @@ import java.io.IOException; return; } handler.sendEmptyMessage(MSG_RELEASE); + boolean wasInterrupted = false; while (!released) { try { wait(); } catch (InterruptedException e) { - Thread.currentThread().interrupt(); + wasInterrupted = true; } } + if (wasInterrupted) { + // Restore the interrupted status. + Thread.currentThread().interrupt(); + } internalPlaybackThread.quit(); }