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

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

Issue 1384303002: Add ThreadChecker class to ThreadUtils (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 2 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 | « no previous file | 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 e7dc331103eab0b75cdefd57e3363a887119243e..5e6cc52895c8ce44fb63201f632c3cb269044777 100644
--- a/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java
+++ b/talk/app/webrtc/java/android/org/webrtc/ThreadUtils.java
@@ -31,6 +31,26 @@ import java.util.concurrent.CountDownLatch;
final class ThreadUtils {
/**
+ * Utility class to be used for checking that a method is called on the correct thread.
+ */
+ public static class ThreadChecker {
+ private Thread thread = Thread.currentThread();
+
+ public void checkIsOnValidThread() {
+ if (thread == null) {
+ thread = Thread.currentThread();
+ }
+ if (Thread.currentThread() != thread) {
+ throw new IllegalStateException("Wrong thread");
+ }
+ }
+
+ public void detachThread() {
+ thread = null;
+ }
+ }
+
+ /**
* Utility interface to be used with executeUninterruptibly() to wait for blocking operations
* to complete without getting interrupted..
*/
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698