aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiogo Ferreira <diogo@underdev.org>2016-10-04 15:37:57 +0100
committerDiogo Ferreira <deovferreira@gmail.com>2016-10-04 07:41:23 -0700
commitbd70b8a02c25c9721bc6f70486b51b8d78187101 (patch)
tree2200407f74294434a2f1cc25fd437d3525559688
parent578f0a0ed7870b5a8ed28c7c0198a798b389a682 (diff)
downloadandroid_packages_apps_CMFileManager-cm-14.0.tar.gz
android_packages_apps_CMFileManager-cm-14.0.tar.bz2
android_packages_apps_CMFileManager-cm-14.0.zip
FileManager: Editor: Fix race on completion wait/notifycm-14.0
The async reader is racing with the completion handler and when reading a small enough file the notification may happen before the handler ever waits. This patch adds a condition flag under the mSync lock and only ever waits if the completion wasn't done already. This also fixes a potential spurious wakeup issue with the previous code where the wait thread could be woken by a spurious wakeup without the read being completed. Change-Id: Ie3e6ead942c0f00dbb3e44591be19634706ee206
-rw-r--r--src/com/cyanogenmod/filemanager/activities/EditorActivity.java6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/com/cyanogenmod/filemanager/activities/EditorActivity.java b/src/com/cyanogenmod/filemanager/activities/EditorActivity.java
index 6f74fcab..9c563797 100644
--- a/src/com/cyanogenmod/filemanager/activities/EditorActivity.java
+++ b/src/com/cyanogenmod/filemanager/activities/EditorActivity.java
@@ -274,6 +274,7 @@ public class EditorActivity extends Activity implements TextWatcher {
private class AsyncReader implements AsyncResultListener {
final Object mSync = new Object();
+ boolean mReadDoneLocked = false;
ByteArrayOutputStream mByteBuffer = null;
ArrayList<String> mBinaryBuffer = null;
SpannableStringBuilder mBuffer = null;
@@ -325,6 +326,7 @@ public class EditorActivity extends Activity implements TextWatcher {
@Override
public void onAsyncExitCode(int exitCode) {
synchronized (this.mSync) {
+ mReadDoneLocked = true;
this.mSync.notify();
}
}
@@ -1277,7 +1279,9 @@ public class EditorActivity extends Activity implements TextWatcher {
// Wait for
synchronized (this.mReader.mSync) {
- this.mReader.mSync.wait();
+ while (!this.mReader.mReadDoneLocked) {
+ this.mReader.mSync.wait();
+ }
}
// 100%