aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiogo Ferreira <diogo@underdev.org>2016-10-04 15:37:57 +0100
committerAdrian DC <radian.dc@gmail.com>2016-12-03 22:56:49 +0100
commite0da075dcc83d9e8e1e863e62efa7dbe797ecfd3 (patch)
tree4dbb3a24c063444dff4a057477670eda9c213301
parent7a2371097753d807afd27b76a109547bc346b3f4 (diff)
downloadandroid_packages_apps_CMFileManager-e0da075dcc83d9e8e1e863e62efa7dbe797ecfd3.tar.gz
android_packages_apps_CMFileManager-e0da075dcc83d9e8e1e863e62efa7dbe797ecfd3.tar.bz2
android_packages_apps_CMFileManager-e0da075dcc83d9e8e1e863e62efa7dbe797ecfd3.zip
FileManager: Editor: Fix race on completion wait/notify
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. RM-290 Change-Id: Ie3e6ead942c0f00dbb3e44591be19634706ee206 Ticket: FEIJAO-1558
-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 c99b11c6..7436fd6b 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();
}
}
@@ -1284,7 +1286,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%