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 b078cb8b19c2405c9c68d410a46e6ee20c93a01d..bd4fa44b9a8f9e7d289fedecc57dc382378b063a 100644 |
--- a/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java |
+++ b/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java |
@@ -88,6 +88,29 @@ final class ThreadUtils { |
} |
} |
+ public static boolean joinUninterruptibly(final Thread thread, long timeoutMs) { |
henrika_webrtc
2015/11/16 10:00:27
Nit, above 80?
magjed_webrtc
2015/11/16 12:12:14
Yes, but the limit is 100 for java files.
|
+ final long startTimeMs = SystemClock.elapsedRealtime(); |
+ long timeRemainingMs = timeoutMs; |
+ boolean wasInterrupted = false; |
+ while (timeRemainingMs > 0) { |
+ try { |
+ thread.join(timeRemainingMs); |
+ break; |
+ } catch (InterruptedException e) { |
+ // 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; |
+ final long elapsedTimeMs = SystemClock.elapsedRealtime() - startTimeMs; |
+ timeRemainingMs = timeoutMs - elapsedTimeMs; |
+ } |
+ } |
+ // Pass interruption information along. |
+ if (wasInterrupted) { |
+ Thread.currentThread().interrupt(); |
+ } |
+ return !thread.isAlive(); |
+ } |
+ |
public static void joinUninterruptibly(final Thread thread) { |
executeUninterruptibly(new BlockingOperation() { |
@Override |