diff options
author | Diogo Ferreira <diogo@underdev.org> | 2016-10-04 15:37:57 +0100 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2016-11-01 10:52:33 -0700 |
commit | 740efc638e209bfe268bcd60f52b23a36372e92e (patch) | |
tree | 2429294f8712122a56847f42bcd938bf5ff3e8ce | |
parent | 52f0f09df4121b08c3a717a5e8cceec0418ad9b6 (diff) | |
download | android_packages_apps_CMFileManager-740efc638e209bfe268bcd60f52b23a36372e92e.tar.gz android_packages_apps_CMFileManager-740efc638e209bfe268bcd60f52b23a36372e92e.tar.bz2 android_packages_apps_CMFileManager-740efc638e209bfe268bcd60f52b23a36372e92e.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.
Change-Id: Ie3e6ead942c0f00dbb3e44591be19634706ee206
Ticket: FEIJAO-1558
-rw-r--r-- | src/com/cyanogenmod/filemanager/activities/EditorActivity.java | 6 |
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% |