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

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

Issue 1356293002: Android: Add class ThreadUtils with helper function joinUninterruptibly() (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rename to ThreadUtils and add extra comment 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/SurfaceViewRenderer.java ('k') | talk/libjingle.gyp » ('j') | 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/src/org/webrtc/CallSessionFileRotatingLogSink.java b/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java
similarity index 63%
copy from talk/app/webrtc/java/src/org/webrtc/CallSessionFileRotatingLogSink.java
copy to talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java
index f7032a739bdbb24ac93dc000b9a42fb11223cc40..d57ff65bb4783003a8ffc5fc4d9b257d1421f506 100644
--- a/talk/app/webrtc/java/src/org/webrtc/CallSessionFileRotatingLogSink.java
+++ b/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java
@@ -27,31 +27,27 @@
package org.webrtc;
-public class CallSessionFileRotatingLogSink {
- static {
- System.loadLibrary("jingle_peerconnection_so");
- }
-
- private long nativeSink;
-
- public static byte[] getLogData(String dirPath) {
- return nativeGetLogData(dirPath);
- }
-
- public CallSessionFileRotatingLogSink(
- String dirPath, int maxFileSize, Logging.Severity severity) {
- nativeSink = nativeAddSink(dirPath, maxFileSize, severity.ordinal());
- }
-
- public void dispose() {
- if (nativeSink != 0) {
- nativeDeleteSink(nativeSink);
- nativeSink = 0;
+public 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().
+ */
+ public static void joinUninterruptibly(Thread thread) {
+ boolean wasInterrupted = false;
+ while (true) {
+ try {
+ thread.join();
+ break;
+ } catch (InterruptedException e) {
+ // Someone is asking us to return early at our convenience. We can't cancel this join(),
+ // but we should preserve the information and pass it along.
+ wasInterrupted = true;
+ }
+ }
+ // Pass interruption information along.
+ if (wasInterrupted) {
+ Thread.currentThread().interrupt();
}
}
-
- private static native long nativeAddSink(
- String dirPath, int maxFileSize, int severity);
- private static native void nativeDeleteSink(long nativeSink);
- private static native byte[] nativeGetLogData(String dirPath);
}
« no previous file with comments | « talk/app/webrtc/java/android/org/webrtc/SurfaceViewRenderer.java ('k') | talk/libjingle.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698