Yell if NDC callers are holding bad locks.

The current MountService design heavily depends on down-callers not
holding any locks, since the vast majority of events are unsolicited
and bubble up to the framework.

This simple API gives us an easy way to track down people calling
while holding a lock they shouldn't be.

Bug: 25443096
Change-Id: Ifcbda95f00d5be8c1b88d58ca67927e76c713c3e
This commit is contained in:
Jeff Sharkey
2015-11-03 10:39:42 -08:00
parent 077f2c9c6b
commit c109706f45

View File

@@ -25,6 +25,7 @@ import android.os.Message;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.LocalLog; import android.util.LocalLog;
import android.util.Log;
import android.util.Slog; import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
@@ -57,6 +58,7 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo
private LocalLog mLocalLog; private LocalLog mLocalLog;
private volatile boolean mDebug = false; private volatile boolean mDebug = false;
private volatile Object mLockWarning;
private final ResponseQueue mResponseQueue; private final ResponseQueue mResponseQueue;
@@ -107,6 +109,14 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo
mDebug = debug; mDebug = debug;
} }
/**
* Yell loudly if someone tries making future {@link #execute(Command)} calls while holding a
* lock on the given object.
*/
public void setLockWarning(Object lockWarning) {
mLockWarning = lockWarning;
}
@Override @Override
public void run() { public void run() {
mCallbackHandler = new Handler(mLooper, this); mCallbackHandler = new Handler(mLooper, this);
@@ -394,6 +404,10 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo
*/ */
public NativeDaemonEvent[] executeForList(long timeoutMs, String cmd, Object... args) public NativeDaemonEvent[] executeForList(long timeoutMs, String cmd, Object... args)
throws NativeDaemonConnectorException { throws NativeDaemonConnectorException {
if (mLockWarning != null && Thread.holdsLock(mLockWarning)) {
Log.wtf(TAG, "Calling thread is holding lock " + mLockWarning, new Throwable());
}
final long startTime = SystemClock.elapsedRealtime(); final long startTime = SystemClock.elapsedRealtime();
final ArrayList<NativeDaemonEvent> events = Lists.newArrayList(); final ArrayList<NativeDaemonEvent> events = Lists.newArrayList();