From c724864c612d899b7942f007c58a2727ce31b7ad Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Mon, 22 Sep 2014 10:25:51 +0900 Subject: [PATCH] Create DictionaryStats in executor. Bug: 16553957 Change-Id: Ie4e9a6ee67f90ba0086af2075068e078efc7f189 --- .../latin/ExpandableBinaryDictionary.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index ad967c133..53abd2ecc 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -27,6 +27,7 @@ import com.android.inputmethod.latin.makedict.UnsupportedFormatException; import com.android.inputmethod.latin.makedict.WordProperty; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion; +import com.android.inputmethod.latin.utils.AsyncResultHolder; import com.android.inputmethod.latin.utils.CombinedFormatUtils; import com.android.inputmethod.latin.utils.DistracterFilter; import com.android.inputmethod.latin.utils.ExecutorUtils; @@ -645,13 +646,15 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { public DictionaryStats getDictionaryStats() { reloadDictionaryIfRequired(); - mLock.readLock().lock(); - try { - // TODO: Get stats form the dictionary. - return new DictionaryStats(mLocale, mDictName, mDictFile); - } finally { - mLock.readLock().unlock(); - } + final AsyncResultHolder result = new AsyncResultHolder<>(); + asyncExecuteTaskWithLock(mLock.readLock(), mDictName /* executorName */, new Runnable() { + @Override + public void run() { + // TODO: Get stats from the dictionary. + result.set(new DictionaryStats(mLocale, mDictName, mDictFile)); + } + }); + return result.get(null /* defaultValue */, TIMEOUT_FOR_READ_OPS_IN_MILLISECONDS); } @UsedForTesting