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

Commit 3c4f362a authored by Rohit Yengisetty's avatar Rohit Yengisetty Committed by Adnan Begovic
Browse files

CM File Manager - Make AsyncResultExecutable's cancel() and end() innocuous

Ensure that cancel() and end() calls don't block the current thread
unnecessarily waiting for a notify().

Change-Id: I05843c8e1bdf880243e1fe9a226809aeaf33986b
parent 5d7137a7
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -241,6 +241,7 @@ public class SearchActivity extends Activity
                @Override
                public void run() {
                    try {
                        mExecutable = null;
                        mAdapter.stopStreaming();
                        int resultsSize = mAdapter.resultsSize();
                        mStreamingSearchProgress.setVisibility(View.INVISIBLE);
@@ -481,7 +482,7 @@ public class SearchActivity extends Activity
        super.onPause();
        // stop search if the activity moves out of the foreground
        if (mExecutable != null) {
            mExecutable.cancel();
            mExecutable.end();
        }
    }

@@ -973,7 +974,7 @@ public class SearchActivity extends Activity
            case KeyEvent.KEYCODE_BACK:
                // release Console lock held by the async search task
                if (mExecutable != null) {
                    mExecutable.cancel();
                    mExecutable.end();
                }
                back(true, null, false);
                return true;
@@ -991,7 +992,7 @@ public class SearchActivity extends Activity
          case android.R.id.home:
              // release Console lock held by the async search task
              if (mExecutable != null) {
                  mExecutable.cancel();
                  mExecutable.end();
              }
              back(true, null, false);
              return true;
@@ -1008,7 +1009,7 @@ public class SearchActivity extends Activity
        // cancel search query if in progress
        // *need* to do this as the async query holds a lock on the Console and we need the Console
        // to gather additional file info in order to process the click event
        if (mSearchInProgress) mExecutable.cancel();
        if (mSearchInProgress) mExecutable.end();

        try {
            SearchResult result = ((SearchResultAdapter)parent.getAdapter()).getItem(position);
+22 −6
Original line number Diff line number Diff line
@@ -43,8 +43,8 @@ public class FindCommand extends Program implements FindExecutable {
    private final String[] mQueryRegExp;
    private final ConcurrentAsyncResultListener mAsyncResultListener;

    private boolean mCancelled;
    private boolean mEnded;
    private volatile boolean mCancelled;
    private volatile boolean mEnded;
    private final Object mSync = new Object();

    /**
@@ -110,6 +110,15 @@ public class FindCommand extends Program implements FindExecutable {
            findRecursive(f);
        }

        // record program's execution termination
        synchronized (mSync) {
            mEnded = true;
            // account for the delay between the end of findRecursive and setting program
            // termination flag (mEnded)
            // notify again in case a thread entered wait state since
            mSync.notify();
        }

        if (this.mAsyncResultListener != null) {
            this.mAsyncResultListener.onAsyncEnd(this.mCancelled);
        }
@@ -187,9 +196,13 @@ public class FindCommand extends Program implements FindExecutable {
    public boolean cancel() {
        try {
            synchronized (this.mSync) {
                // ensure the program is running before attempting to cancel
                // there won't be a corresponding lock.notify() otherwise
                if (!mEnded) {
                    this.mCancelled = true;
                    this.mSync.wait(5000L);
                }
            }
        } catch (Exception e) {/**NON BLOCK**/}
        return true;
    }
@@ -201,9 +214,12 @@ public class FindCommand extends Program implements FindExecutable {
    public boolean end() {
        try {
            synchronized (this.mSync) {
                // ensure the program is running before attempting to terminate
                if (!mEnded) {
                    this.mEnded = true;
                    this.mSync.wait(5000L);
                }
            }
        } catch (Exception e) {/**NON BLOCK**/}
        return true;
    }
+16 −4
Original line number Diff line number Diff line
@@ -44,8 +44,8 @@ public class FindCommand extends Program implements FindExecutable {
    private final String[] mQueryRegExp;
    private final ConcurrentAsyncResultListener mAsyncResultListener;

    private boolean mCancelled;
    private boolean mEnded;
    private volatile boolean mCancelled;
    private volatile boolean mEnded;
    private final Object mSync = new Object();

    /**
@@ -118,6 +118,15 @@ public class FindCommand extends Program implements FindExecutable {
        // Find the data
        findRecursive(f);

        // record program's execution termination
        synchronized (mSync) {
            mEnded = true;
            // account for the delay between the end of findRecursive and setting program
            // termination flag (mEnded)
            // notify again in case a thread entered wait state since
            mSync.notify();
        }

        if (this.mAsyncResultListener != null) {
            this.mAsyncResultListener.onAsyncEnd(this.mCancelled);
        }
@@ -198,7 +207,9 @@ public class FindCommand extends Program implements FindExecutable {
    @Override
    public boolean cancel() {
        try {
            synchronized (this.mSync) {
            // ensure the program is running before attempting to cancel
            // there won't be a corresponding lock.notify() otherwise
            if (!mEnded) {
                this.mCancelled = true;
                this.mSync.wait(5000L);
            }
@@ -212,7 +223,8 @@ public class FindCommand extends Program implements FindExecutable {
    @Override
    public boolean end() {
        try {
            synchronized (this.mSync) {
            // ensure the program is running before attempting to terminate
            if (!mEnded) {
                this.mEnded = true;
                this.mSync.wait(5000L);
            }