Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f695d3ae authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Yell if NDC callers are holding bad locks."

parents 9f591aeb e41dc596
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1440,6 +1440,7 @@ class MountService extends IMountService.Stub
        mConnector = new NativeDaemonConnector(this, "vold", MAX_CONTAINERS * 2, VOLD_TAG, 25,
                null);
        mConnector.setDebug(true);
        mConnector.setLockWarning(mLock);

        Thread thread = new Thread(mConnector, VOLD_TAG);
        thread.start();
+14 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.os.Message;
import android.os.PowerManager;
import android.os.SystemClock;
import android.util.LocalLog;
import android.util.Log;
import android.util.Slog;

import com.android.internal.annotations.VisibleForTesting;
@@ -57,6 +58,7 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo
    private LocalLog mLocalLog;

    private volatile boolean mDebug = false;
    private volatile Object mLockWarning;

    private final ResponseQueue mResponseQueue;

@@ -107,6 +109,14 @@ final class NativeDaemonConnector implements Runnable, Handler.Callback, Watchdo
        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
    public void run() {
        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)
            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 ArrayList<NativeDaemonEvent> events = Lists.newArrayList();