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

Commit 4db2fc7e authored by Jorge Ruesga's avatar Jorge Ruesga
Browse files

CMFM: Fix AsyncResultProgram deadlock



Change-Id: Idd32ef7902eaf86e573728f7e442c281a47249fc
Signed-off-by: default avatarjruesga <jorge@ruesga.com>
parent b6a78033
Loading
Loading
Loading
Loading
+5 −10
Original line number Original line Diff line number Diff line
@@ -131,17 +131,12 @@ public abstract class AsyncResultProgram
            this.mSync.notify();
            this.mSync.notify();
        }
        }
        synchronized (this.mTerminateSync) {
        synchronized (this.mTerminateSync) {
            if (this.mWorkerThread.isAlive()) {
                try {
                try {
                    this.mTerminateSync.wait();
                    this.mTerminateSync.wait();
                } catch (Exception e) {
                } catch (Exception e) {
                    /**NON BLOCK**/
                    /**NON BLOCK**/
                }
                }
            try {
                if (this.mWorkerThread.isAlive()) {
                    this.mWorkerThread.interrupt();
                }
            } catch (Exception e) {
                /**NON BLOCK**/
            }
            }
        }
        }


+5 −5
Original line number Original line Diff line number Diff line
@@ -44,7 +44,7 @@ public class WriteCommand extends AsyncResultProgram implements WriteExecutable
    /**
    /**
     * @hide
     * @hide
     */
     */
    final Object mSync = new Object();
    final Object mWriteSync = new Object();
    private boolean mReady;
    private boolean mReady;
    /**
    /**
     * @hide
     * @hide
@@ -81,10 +81,10 @@ public class WriteCommand extends AsyncResultProgram implements WriteExecutable
    public OutputStream createOutputStream() throws IOException {
    public OutputStream createOutputStream() throws IOException {


        // Wait until command is ready
        // Wait until command is ready
        synchronized (this.mSync) {
        synchronized (this.mWriteSync) {
            if (!this.mReady) {
            if (!this.mReady) {
                try {
                try {
                    this.mSync.wait(TIMEOUT);
                    this.mWriteSync.wait(TIMEOUT);
                } catch (Exception e) {/**NON BLOCK**/}
                } catch (Exception e) {/**NON BLOCK**/}
            }
            }
        }
        }
@@ -96,9 +96,9 @@ public class WriteCommand extends AsyncResultProgram implements WriteExecutable
     */
     */
    @Override
    @Override
    public void onStartParsePartialResult() {
    public void onStartParsePartialResult() {
        synchronized (this.mSync) {
        synchronized (this.mWriteSync) {
            this.mReady = true;
            this.mReady = true;
            this.mSync.notify();
            this.mWriteSync.notify();
        }
        }
    }
    }


+20 −16
Original line number Original line Diff line number Diff line
@@ -1135,6 +1135,7 @@ public abstract class ShellConsole extends Console implements Program.ProgramLis
            if (program.getCommand() != null) {
            if (program.getCommand() != null) {
                try {
                try {
                    if (program.isCancellable()) {
                    if (program.isCancellable()) {
                        try {
                            //Get the PID in background
                            //Get the PID in background
                            Integer pid =
                            Integer pid =
                                    CommandHelper.getProcessId(
                                    CommandHelper.getProcessId(
@@ -1153,10 +1154,13 @@ public abstract class ShellConsole extends Console implements Program.ProgramLis
                                } catch (Throwable ex) {
                                } catch (Throwable ex) {
                                    /**NON BLOCK**/
                                    /**NON BLOCK**/
                                }
                                }
                                return true;
                            }
                        } finally {
                            // It's finished
                            this.mCancelled = true;
                            this.mCancelled = true;
                            notifyProcessFinished();
                            notifyProcessFinished();
                            this.mSync.notify();
                            this.mSync.notify();
                            return this.mCancelled;
                        }
                        }
                    }
                    }
                } catch (Throwable ex) {
                } catch (Throwable ex) {