Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Unified Diff: talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java

Issue 1368093003: Android SurfaceTextureHelper: Don't wait for pending frames in disconnect() (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased and added more comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « talk/app/webrtc/java/android/org/webrtc/SurfaceTextureHelper.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java
diff --git a/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java b/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java
index d57ff65bb4783003a8ffc5fc4d9b257d1421f506..e7dc331103eab0b75cdefd57e3363a887119243e 100644
--- a/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java
+++ b/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java
@@ -27,20 +27,32 @@
package org.webrtc;
-public class ThreadUtils {
+import java.util.concurrent.CountDownLatch;
+
+final class ThreadUtils {
/**
- * Helper function to make sure a thread is joined without getting interrupted. This should be
- * used in cases where |thread| is doing some critical work, e.g. cleanup, that must complete
- * before returning. The thread interruption flag is set if an interrupt occurs during join().
+ * Utility interface to be used with executeUninterruptibly() to wait for blocking operations
+ * to complete without getting interrupted..
*/
- public static void joinUninterruptibly(Thread thread) {
+ public interface BlockingOperation {
+ void run() throws InterruptedException;
+ }
+
+ /**
+ * Utility method to make sure a blocking operation is executed to completion without getting
+ * interrupted. This should be used in cases where the operation is waiting for some critical
+ * work, e.g. cleanup, that must complete before returning. If the thread is interrupted during
+ * the blocking operation, this function will re-run the operation until completion, and only then
+ * re-interrupt the thread.
+ */
+ public static void executeUninterruptibly(BlockingOperation operation) {
boolean wasInterrupted = false;
while (true) {
try {
- thread.join();
+ operation.run();
break;
} catch (InterruptedException e) {
- // Someone is asking us to return early at our convenience. We can't cancel this join(),
+ // Someone is asking us to return early at our convenience. We can't cancel this operation,
// but we should preserve the information and pass it along.
wasInterrupted = true;
}
@@ -50,4 +62,22 @@ public class ThreadUtils {
Thread.currentThread().interrupt();
}
}
+
+ public static void joinUninterruptibly(final Thread thread) {
+ executeUninterruptibly(new BlockingOperation() {
+ @Override
+ public void run() throws InterruptedException {
+ thread.join();
+ }
+ });
+ }
+
+ public static void awaitUninterruptibly(final CountDownLatch latch) {
+ executeUninterruptibly(new BlockingOperation() {
+ @Override
+ public void run() throws InterruptedException {
+ latch.await();
+ }
+ });
+ }
}
« no previous file with comments | « talk/app/webrtc/java/android/org/webrtc/SurfaceTextureHelper.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698