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

Commit 276ae017 authored by Narayan Kamath's avatar Narayan Kamath Committed by Gerrit Code Review
Browse files

Merge "Fix Deadlock Issue On AppFuseBridge"

parents 777fbbb9 2e28bb23
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -56,6 +56,15 @@ public class AppFuseBridge implements Runnable {

    public ParcelFileDescriptor addBridge(MountScope mountScope)
            throws FuseUnavailableMountException, NativeDaemonConnectorException {
        /*
        ** Dead Lock between Java lock (AppFuseBridge.java) and Native lock (FuseBridgeLoop.cc)
        **
        **  (Thread A) Got Java lock (addBrdige) -> Try to get Native lock (native_add_brdige)
        **  (Thread B)        Got Native lock (FuseBrdigeLoop.start) -> Try to get Java lock (onClosed)
        **
        ** Guarantee the lock order (native lock -> java lock) when adding Bridge.
        */
        native_lock();
        try {
            synchronized (this) {
                Preconditions.checkArgument(mScopes.indexOfKey(mountScope.mountId) < 0);
@@ -73,6 +82,7 @@ public class AppFuseBridge implements Runnable {
                return result;
            }
        } finally {
            native_unlock();
            IoUtils.closeQuietly(mountScope);
        }
    }
@@ -159,4 +169,6 @@ public class AppFuseBridge implements Runnable {
    private native void native_delete(long loop);
    private native void native_start_loop(long loop);
    private native int native_add_bridge(long loop, int mountId, int deviceId);
    private native void native_lock();
    private native void native_unlock();
}
+18 −0
Original line number Diff line number Diff line
@@ -123,6 +123,14 @@ jint com_android_server_storage_AppFuseBridge_add_bridge(
    return proxyFd[1].release();
}

void com_android_server_storage_AppFuseBridge_lock(JNIEnv* env, jobject self) {
    fuse::FuseBridgeLoop::Lock();
}

void com_android_server_storage_AppFuseBridge_unlock(JNIEnv* env, jobject self) {
    fuse::FuseBridgeLoop::Unlock();
}

const JNINativeMethod methods[] = {
    {
        "native_new",
@@ -143,6 +151,16 @@ const JNINativeMethod methods[] = {
        "native_add_bridge",
        "(JII)I",
        reinterpret_cast<void*>(com_android_server_storage_AppFuseBridge_add_bridge)
    },
    {
        "native_lock",
        "()V",
        reinterpret_cast<void*>(com_android_server_storage_AppFuseBridge_lock)
    },
    {
        "native_unlock",
        "()V",
        reinterpret_cast<void*>(com_android_server_storage_AppFuseBridge_unlock)
    }
};