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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 13 matching lines...) Expand all
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 package org.webrtc; 28 package org.webrtc;
29 29
30 import java.util.concurrent.CountDownLatch; 30 import java.util.concurrent.CountDownLatch;
31 31
32 final class ThreadUtils { 32 final class ThreadUtils {
33 /** 33 /**
34 * Utility class to be used for checking that a method is called on the correc t thread.
35 */
36 public static class ThreadChecker {
37 private Thread thread = Thread.currentThread();
38
39 public void checkIsOnValidThread() {
40 if (thread == null) {
41 thread = Thread.currentThread();
42 }
43 if (Thread.currentThread() != thread) {
44 throw new IllegalStateException("Wrong thread");
45 }
46 }
47
48 public void detachThread() {
49 thread = null;
50 }
51 }
52
53 /**
34 * Utility interface to be used with executeUninterruptibly() to wait for bloc king operations 54 * Utility interface to be used with executeUninterruptibly() to wait for bloc king operations
35 * to complete without getting interrupted.. 55 * to complete without getting interrupted..
36 */ 56 */
37 public interface BlockingOperation { 57 public interface BlockingOperation {
38 void run() throws InterruptedException; 58 void run() throws InterruptedException;
39 } 59 }
40 60
41 /** 61 /**
42 * Utility method to make sure a blocking operation is executed to completion without getting 62 * Utility method to make sure a blocking operation is executed to completion without getting
43 * interrupted. This should be used in cases where the operation is waiting fo r some critical 63 * interrupted. This should be used in cases where the operation is waiting fo r some critical
(...skipping 30 matching lines...) Expand all
74 94
75 public static void awaitUninterruptibly(final CountDownLatch latch) { 95 public static void awaitUninterruptibly(final CountDownLatch latch) {
76 executeUninterruptibly(new BlockingOperation() { 96 executeUninterruptibly(new BlockingOperation() {
77 @Override 97 @Override
78 public void run() throws InterruptedException { 98 public void run() throws InterruptedException {
79 latch.await(); 99 latch.await();
80 } 100 }
81 }); 101 });
82 } 102 }
83 } 103 }
OLDNEW
« 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