Add ThreadChecker class to ThreadUtils
This class can be used for checking that method calls are made on the correct thread. R=magjed@webrtc.org Review URL: https://codereview.webrtc.org/1384303002 . Cr-Commit-Position: refs/heads/master@{#10173}
This commit is contained in:
@ -30,6 +30,26 @@ package org.webrtc;
|
||||
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..
|
||||
|
Reference in New Issue
Block a user